summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-02-07 10:27:03 -0800
committerDylan Baker <dylan@pnwbakers.com>2017-02-07 10:45:55 -0800
commit4e24022be56f5cc072f2f536959ada9e8b0ecda7 (patch)
tree9a0aab45cbd8bb087c12fd3a90f7d7526e723398 /tests
parenta69b0810f4a8a706df877392869828585b79ca0f (diff)
tests/helper_test.py: Add tests for call_cmd
This even finds a bug!
Diffstat (limited to 'tests')
-rw-r--r--tests/helper_test.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/helper_test.py b/tests/helper_test.py
index 4a97bb7e..a2a2b925 100644
--- a/tests/helper_test.py
+++ b/tests/helper_test.py
@@ -20,6 +20,7 @@
from __future__ import absolute_import
import datetime
+import errno
import random
import unittest
@@ -27,6 +28,13 @@ import mock
from alot import helper
+# Descriptive names for tests often violate PEP8. That's not an issue, users
+# aren't meant to call these functions.
+# pylint: disable=invalid-name
+
+# They're tests, only add docstrings when it makes sense
+# pylint: disable=missing-docstring
+
class TestHelperShortenAuthorString(unittest.TestCase):
@@ -303,3 +311,64 @@ class TestPrettyDatetime(unittest.TestCase):
actual = helper.pretty_datetime(test)
expected = test.strftime('%b %Y')
self.assertEqual(actual, expected)
+
+
+class TestCallCmd(unittest.TestCase):
+ """Tests for the call_cmd function."""
+
+ def test_no_stdin(self):
+ out, err, code = helper.call_cmd(['echo', '-n', 'foo'])
+ self.assertEqual(out, u'foo')
+ self.assertEqual(err, u'')
+ self.assertEqual(code, 0)
+
+ def test_no_stdin_unicode(self):
+ out, err, code = helper.call_cmd(['echo', '-n', '�'])
+ self.assertEqual(out, u'�')
+ self.assertEqual(err, u'')
+ self.assertEqual(code, 0)
+
+ def test_stdin(self):
+ out, err, code = helper.call_cmd(['cat'], stdin='�')
+ self.assertEqual(out, u'�')
+ self.assertEqual(err, u'')
+ self.assertEqual(code, 0)
+
+ def test_no_such_command(self):
+ out, err, code = helper.call_cmd(['thiscommandabsolutelydoesntexist'])
+ self.assertEqual(out, u'')
+
+ # We don't control the output of err, the shell does. Therefore simply
+ # assert that the shell said *something*
+ self.assertNotEqual(err, u'')
+ self.assertEqual(code, errno.ENOENT)
+
+ def test_no_such_command_stdin(self):
+ out, err, code = helper.call_cmd(['thiscommandabsolutelydoesntexist'],
+ stdin='foo')
+ self.assertEqual(out, u'')
+
+ # We don't control the output of err, the shell does. Therefore simply
+ # assert that the shell said *something*
+ self.assertNotEqual(err, u'')
+ self.assertEqual(code, errno.ENOENT)
+
+ def test_bad_argument_stdin(self):
+ out, err, code = helper.call_cmd(['cat', '-Y'], stdin='�')
+ self.assertEqual(out, u'')
+ self.assertNotEqual(err, u'')
+
+ # 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)
+
+ # This fails because stderr is not recorded correctly
+ @unittest.expectedFailure
+ def test_bad_argument(self):
+ out, err, code = helper.call_cmd(['cat', '-Y'])
+ self.assertEqual(out, u'')
+ self.assertNotEqual(err, u'')
+
+ # 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)