diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-21 20:26:52 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-21 20:26:52 (GMT) |
commit | 65fd0592fb3845c17b27c441380553fc22f78812 (patch) | |
tree | 514cb4f7fb01bcc581922bee799c3bfbe58a9cd2 /Lib/test | |
parent | f7d2874d3097054e030f0169f5eed92af488acbe (diff) | |
download | cpython-65fd0592fb3845c17b27c441380553fc22f78812.zip cpython-65fd0592fb3845c17b27c441380553fc22f78812.tar.gz cpython-65fd0592fb3845c17b27c441380553fc22f78812.tar.bz2 |
Issue #2382: SyntaxError cursor "^" now is written at correct position in most
cases when multibyte characters are in line (before "^"). This still not
works correctly with wide East Asian characters.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_exceptions.py | 13 | ||||
-rw-r--r-- | Lib/test/test_traceback.py | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 1ad7f97..fe660bf 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -148,6 +148,19 @@ class ExceptionTests(unittest.TestCase): ckmsg(s, "'continue' not properly in loop") ckmsg("continue\n", "'continue' not properly in loop") + def testSyntaxErrorOffset(self): + def check(src, lineno, offset): + with self.assertRaises(SyntaxError) as cm: + compile(src, '<fragment>', 'exec') + self.assertEqual(cm.exception.lineno, lineno) + self.assertEqual(cm.exception.offset, offset) + + check('def fact(x):\n\treturn x!\n', 2, 10) + check('1 +\n', 1, 4) + check('def spam():\n print(1)\n print(2)', 3, 10) + check('Python = "Python" +', 1, 20) + check('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', 1, 20) + @cpython_only def testSettingException(self): # test that setting an exception at the C level works even if the diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index bca825d..373d9af 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -32,6 +32,9 @@ class SyntaxTracebackCases(unittest.TestCase): def syntax_error_bad_indentation(self): compile("def spam():\n print(1)\n print(2)", "?", "exec") + def syntax_error_with_caret_non_ascii(self): + compile('Python = "\u1e54\xfd\u0163\u0125\xf2\xf1" +', "?", "exec") + def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, SyntaxError) @@ -46,6 +49,12 @@ class SyntaxTracebackCases(unittest.TestCase): self.assertTrue(err[2].count('\n') == 1) # and no additional newline self.assertTrue(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 + def test_nocaret(self): exc = SyntaxError("error", ("x.py", 23, None, "bad syntax")) err = traceback.format_exception_only(SyntaxError, exc) |