diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-01-22 00:16:25 (GMT) |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-01-22 00:16:25 (GMT) |
commit | 45e124e26d43d4618d2686b5323c322aa25566b6 (patch) | |
tree | a9e3d1f32968eab28c098f48afa0dbf4c36d8528 /Lib/test/test_traceback.py | |
parent | f1e4fdcf16f84fe1b065fb7d65390d9e2724afa9 (diff) | |
parent | 758fa5ea819d4301afed5049fa1186f275c4f801 (diff) | |
download | cpython-45e124e26d43d4618d2686b5323c322aa25566b6.zip cpython-45e124e26d43d4618d2686b5323c322aa25566b6.tar.gz cpython-45e124e26d43d4618d2686b5323c322aa25566b6.tar.bz2 |
Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError.
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r-- | Lib/test/test_traceback.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index a6ae1e5..8e71363 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -35,6 +35,9 @@ class SyntaxTracebackCases(unittest.TestCase): def syntax_error_with_caret_non_ascii(self): compile('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', "?", "exec") + def syntax_error_bad_indentation2(self): + compile(" print(2)", "?", "exec") + def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, SyntaxError) @@ -46,14 +49,14 @@ class SyntaxTracebackCases(unittest.TestCase): err = self.get_exception_format(self.syntax_error_with_caret_2, SyntaxError) self.assertIn("^", err[2]) # third line has caret - self.assertTrue(err[2].count('\n') == 1) # and no additional newline - self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place + self.assertEqual(err[2].count('\n'), 1) # and no additional newline + self.assertEqual(err[1].find("+"), err[2].find("^")) # in the right place err = self.get_exception_format(self.syntax_error_with_caret_non_ascii, SyntaxError) self.assertIn("^", err[2]) # third line has caret - self.assertTrue(err[2].count('\n') == 1) # and no additional newline - self.assertTrue(err[1].find("+") == err[2].find("^")) # in the right place + self.assertEqual(err[2].count('\n'), 1) # and no additional newline + self.assertEqual(err[1].find("+"), err[2].find("^")) # in the right place def test_nocaret(self): exc = SyntaxError("error", ("x.py", 23, None, "bad syntax")) @@ -69,6 +72,13 @@ class SyntaxTracebackCases(unittest.TestCase): self.assertIn("^", err[2]) self.assertEqual(err[1].find(")"), err[2].find("^")) + err = self.get_exception_format(self.syntax_error_bad_indentation2, + IndentationError) + self.assertEqual(len(err), 4) + self.assertEqual(err[1].strip(), "print(2)") + self.assertIn("^", err[2]) + self.assertEqual(err[1].find("p"), err[2].find("^")) + def test_base_exception(self): # Test that exceptions derived from BaseException are formatted right e = KeyboardInterrupt() |