diff options
| author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-09-27 20:59:06 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-27 20:59:06 (GMT) |
| commit | 20f439b6b9e1032930a31b88694ab9f37a09e6b4 (patch) | |
| tree | b8f430c4fa0048bbca33b52770e2cd3c13a6b6aa /Lib/test/test_traceback.py | |
| parent | adc5d32f474595aa16a90369393440a0bc190777 (diff) | |
| download | cpython-20f439b6b9e1032930a31b88694ab9f37a09e6b4.zip cpython-20f439b6b9e1032930a31b88694ab9f37a09e6b4.tar.gz cpython-20f439b6b9e1032930a31b88694ab9f37a09e6b4.tar.bz2 | |
bpo-45249: Ensure the traceback module prints correctly syntax errors with ranges (GH-28575)
Diffstat (limited to 'Lib/test/test_traceback.py')
| -rw-r--r-- | Lib/test/test_traceback.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 363165d..83d36e1 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -43,6 +43,9 @@ class TracebackCases(unittest.TestCase): def syntax_error_with_caret_2(self): compile("1 +\n", "?", "exec") + def syntax_error_with_caret_range(self): + compile("f(x, y for y in range(30), z)", "?", "exec") + def syntax_error_bad_indentation(self): compile("def spam():\n print(1)\n print(2)", "?", "exec") @@ -59,18 +62,28 @@ class TracebackCases(unittest.TestCase): self.assertTrue(err[1].strip() == "return x!") self.assertIn("^", err[2]) # third line has caret self.assertEqual(err[1].find("!"), err[2].find("^")) # in the right place + self.assertEqual(err[2].count("^"), 1) err = self.get_exception_format(self.syntax_error_with_caret_2, SyntaxError) self.assertIn("^", err[2]) # third line has caret self.assertEqual(err[2].count('\n'), 1) # and no additional newline self.assertEqual(err[1].find("+") + 1, err[2].find("^")) # in the right place + self.assertEqual(err[2].count("^"), 1) err = self.get_exception_format(self.syntax_error_with_caret_non_ascii, SyntaxError) self.assertIn("^", err[2]) # third line has caret self.assertEqual(err[2].count('\n'), 1) # and no additional newline self.assertEqual(err[1].find("+") + 1, err[2].find("^")) # in the right place + self.assertEqual(err[2].count("^"), 1) + + err = self.get_exception_format(self.syntax_error_with_caret_range, + SyntaxError) + self.assertIn("^", err[2]) # third line has caret + self.assertEqual(err[2].count('\n'), 1) # and no additional newline + self.assertEqual(err[1].find("y"), err[2].find("^")) # in the right place + self.assertEqual(err[2].count("^"), len("y for y in range(30)")) def test_nocaret(self): exc = SyntaxError("error", ("x.py", 23, None, "bad syntax")) |
