From 69359662aa0f9ead18f50b8f99939656550d63af Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 2 Feb 2017 23:23:14 +0100 Subject: Add tests for OSError handling in alot.helper.call_cmd --- tests/helper_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') 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) -- cgit v1.2.3