diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-05-12 09:42:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-12 09:42:04 (GMT) |
commit | 74ea6b5a7501fb393cd567fb21998d0bfeeb267c (patch) | |
tree | 6f82cb1ae91f9cc21e0181f7284039b7d58d0309 /Lib | |
parent | f3a5b7ada0c951f317dbd307de4b410e58d3e1b3 (diff) | |
download | cpython-74ea6b5a7501fb393cd567fb21998d0bfeeb267c.zip cpython-74ea6b5a7501fb393cd567fb21998d0bfeeb267c.tar.gz cpython-74ea6b5a7501fb393cd567fb21998d0bfeeb267c.tar.bz2 |
bpo-40593: Improve syntax errors for invalid characters in source code. (GH-20033)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_fstring.py | 2 | ||||
-rw-r--r-- | Lib/test/test_source_encoding.py | 3 | ||||
-rw-r--r-- | Lib/test/test_unicode_identifiers.py | 8 |
3 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py index ac5aa9a..e0bb5b5 100644 --- a/Lib/test/test_fstring.py +++ b/Lib/test/test_fstring.py @@ -583,7 +583,7 @@ non-important content ]) # Different error message is raised for other whitespace characters. - self.assertAllRaise(SyntaxError, 'invalid character in identifier', + self.assertAllRaise(SyntaxError, r"invalid non-printable character U\+00A0", ["f'''{\xa0}'''", "\xa0", ]) diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py index a0bd741..5ca4346 100644 --- a/Lib/test/test_source_encoding.py +++ b/Lib/test/test_source_encoding.py @@ -57,6 +57,9 @@ class MiscSourceEncodingTest(unittest.TestCase): # one byte in common with the UTF-16-LE BOM self.assertRaises(SyntaxError, eval, b'\xff\x20') + # one byte in common with the UTF-8 BOM + self.assertRaises(SyntaxError, eval, b'\xef\x20') + # two bytes in common with the UTF-8 BOM self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20') diff --git a/Lib/test/test_unicode_identifiers.py b/Lib/test/test_unicode_identifiers.py index 07332c4..5b9ced5 100644 --- a/Lib/test/test_unicode_identifiers.py +++ b/Lib/test/test_unicode_identifiers.py @@ -20,9 +20,11 @@ class PEP3131Test(unittest.TestCase): def test_invalid(self): try: from test import badsyntax_3131 - except SyntaxError as s: - self.assertEqual(str(s), - "invalid character in identifier (badsyntax_3131.py, line 2)") + except SyntaxError as err: + self.assertEqual(str(err), + "invalid character '€' (U+20AC) (badsyntax_3131.py, line 2)") + self.assertEqual(err.lineno, 2) + self.assertEqual(err.offset, 1) else: self.fail("expected exception didn't occur") |