summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2017-02-02 23:23:14 +0100
committerLucas Hoffmann <l-m-h@web.de>2017-02-18 11:55:13 +0100
commit69359662aa0f9ead18f50b8f99939656550d63af (patch)
treea73a44ab782f280cffc1a359f38341e2543dd76d /tests
parent333fcaed50296402aaf24f226d38ff93599bcd25 (diff)
Add tests for OSError handling in alot.helper.call_cmd
Diffstat (limited to 'tests')
-rw-r--r--tests/helper_test.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/helper_test.py b/tests/helper_test.py
index 78cba84d..9ec62cfe 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -370,3 +370,20 @@ class TestCallCmd(unittest.TestCase):
# We don't control this, although 1 might be a fairly safe guess, we
# know for certain it should *not* return 0
self.assertNotEqual(code, 0)
+
+ def test_os_errors_from_popen_are_caught(self):
+ with mock.patch('subprocess.Popen',
+ mock.Mock(side_effect=OSError(42, u'foobar'))):
+ out, err, code = helper.call_cmd(['does_not_matter_as_subprocess_popen_is_mocked'])
+ self.assertEqual(out, u'')
+ self.assertEqual(err, u'foobar')
+ self.assertEqual(code, 42)
+
+ def test_os_errors_from_communicate_are_caught(self):
+ popen = mock.Mock()
+ popen.communicate = mock.Mock(side_effect=OSError(42, u'foobar'))
+ with mock.patch('subprocess.Popen', lambda *args, **kwargs: popen):
+ out, err, code = helper.call_cmd(['does_not_matter_as_subprocess_popen_is_mocked'])
+ self.assertEqual(out, u'')
+ self.assertEqual(err, u'foobar')
+ self.assertEqual(code, 42)