diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-09-27 14:26:39 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-27 14:26:39 -0700 |
| commit | c7fdd6879b5c8447ee65b1bec95a1db43837a7a5 (patch) | |
| tree | 902575e22a452c923910593b7ef4331b9f336d26 /Lib/test/test_traceback.py | |
| parent | 9e209d48cac35108f3955d3f610b6ce60b574ecc (diff) | |
| download | cpython-git-c7fdd6879b5c8447ee65b1bec95a1db43837a7a5.tar.gz | |
bpo-45249: Ensure the traceback module prints correctly syntax errors with ranges (GH-28575)
(cherry picked from commit 20f439b6b9e1032930a31b88694ab9f37a09e6b4)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
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 ee18383478..fabe5d01a9 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -39,6 +39,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") @@ -55,18 +58,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")) |
