diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2021-12-12 07:06:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 07:06:50 (GMT) |
commit | 4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5 (patch) | |
tree | af6a6984dcbce46cad39d8d3fc669909cb36ffc9 /Lib/test/test_exceptions.py | |
parent | 59435eea08d30796174552c0ca03c59b41adf8a5 (diff) | |
download | cpython-4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5.zip cpython-4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5.tar.gz cpython-4325a766f5f603ef6dfb8c4d5798e5e73cb5efd5.tar.bz2 |
bpo-46054: Fix parsing error when parsing non-utf8 characters in source files (GH-30068)
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index c861d8f..1021026 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -2387,6 +2387,18 @@ class SyntaxErrorTests(unittest.TestCase): finally: unlink(TESTFN) + def test_non_utf8(self): + # Check non utf-8 characters + try: + with open(TESTFN, 'bw') as testfile: + testfile.write(b'\x7fELF\x02\x01\x01\x00\x00\x00') + rc, out, err = script_helper.assert_python_failure('-Wd', '-X', 'utf8', TESTFN) + err = err.decode('utf-8').splitlines() + + self.assertEqual(err[-1], "SyntaxError: invalid non-printable character U+007F") + finally: + unlink(TESTFN) + def test_attributes_new_constructor(self): args = ("bad.py", 1, 2, "abcdefg", 1, 100) the_exception = SyntaxError("bad bad", args) |