From ff9d30b60643c85fd30fd5aeceed6a93ea6ca7ec Mon Sep 17 00:00:00 2001 From: Tomaz Solc Date: Sun, 16 Jun 2019 11:04:03 +0200 Subject: [PATCH] Also test command-line utility return code. --- tests/test_utility.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_utility.py b/tests/test_utility.py index c9c6ea7..7a58888 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -26,7 +26,7 @@ def run(argv): out, err = p.communicate() - return out.decode('ascii'), err.decode('ascii') + return out.decode('ascii'), err.decode('ascii'), p.returncode def temp(content): f = tempfile.NamedTemporaryFile() @@ -41,21 +41,24 @@ class TestUnidecodeUtility(unittest.TestCase): def test_encoding_error(self): f = temp(self.TEST_UNICODE.encode('sjis')) - out, err = run(['-e', 'utf8', f.name]) + out, err, rc = run(['-e', 'utf8', f.name]) # Text after : ... can differ between Python versions self.assertRegex(err, '^Unable to decode input: ') + self.assertEqual(rc, 1) def test_file_specified_encoding(self): f = temp(self.TEST_UNICODE.encode('sjis')) - out, err = run(['-e', 'sjis', f.name]) + out, err, rc = run(['-e', 'sjis', f.name]) self.assertEqual(out, self.TEST_ASCII) + self.assertEqual(rc, 0) def test_file_default_encoding(self): f = temp(self.TEST_UNICODE.encode(locale.getpreferredencoding())) - out, err = run([f.name]) + out, err, rc = run([f.name]) self.assertEqual(out, self.TEST_ASCII) + self.assertEqual(rc, 0) def test_file_stdin(self): cmd = get_cmd() @@ -65,5 +68,6 @@ def test_file_stdin(self): self.assertEqual(out.decode('ascii'), self.TEST_ASCII) def test_commandline(self): - out = run(['-e', 'sjis', '-c', self.TEST_UNICODE.encode('sjis')])[0] + out, err, rc = run(['-e', 'sjis', '-c', self.TEST_UNICODE.encode('sjis')]) self.assertEqual(out, self.TEST_ASCII + '\n') + self.assertEqual(rc, 0)