Skip to content

Commit f9afd2b

Browse files
committed
test_errors_syntax: Expect SystemExit error code 1
The test was written to expect SystemExit error code of True. The SystemExit raised by api.main is of type bool. True and 1 are equal, and assertEqual treats them that way, so there is no difference between them. The other tests in this class expect an int error code, due to the use of Popen which will convert the SystemExit bool to an int. Hence this patch switches to using 1. More importantly, TestMain.runPyflakes is updated to check the api.main error code is a bool, and then force the conversion to int, so that any errors from self.assertEqual do not show differences of 1 vs True, when in fact assertEqual considers them to be identical. These differences of 1 vs True are distracting to whatever other differences are presented, especially in error offset bugs like regularly occur, such as #346.
1 parent 06653e4 commit f9afd2b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pyflakes/test/test_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ def test_errors_syntax(self):
757757
d = self.runPyflakes([self.tempfilepath])
758758
error_msg = '{0}:1:{2}: invalid syntax{1}import{1} {3}^{1}'.format(
759759
self.tempfilepath, os.linesep, 5 if PYPY else 7, '' if PYPY else ' ')
760-
self.assertEqual(d, ('', error_msg, True))
760+
self.assertEqual(d, ('', error_msg, 1))
761761

762762
def test_readFromStdin(self):
763763
"""
@@ -778,6 +778,8 @@ def runPyflakes(self, paths, stdin=None):
778778
with SysStreamCapturing(stdin) as capture:
779779
main(args=paths)
780780
except SystemExit as e:
781-
return (capture.output, capture.error, e.code)
781+
self.assertIsInstance(e.code, bool)
782+
rv = int(e.code)
783+
return (capture.output, capture.error, rv)
782784
else:
783785
raise RuntimeError('SystemExit not raised')

0 commit comments

Comments
 (0)