From 05692c67c51b78a5a5a7bb61d646519025e38015 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 6 Sep 2022 19:12:16 -0400 Subject: gh-96611: Fix error message for invalid UTF-8 in mid-multiline string (#96623) --- Lib/test/test_source_encoding.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Lib/test/test_source_encoding.py') diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py index 8e68b4eae33..feaff4770f7 100644 --- a/Lib/test/test_source_encoding.py +++ b/Lib/test/test_source_encoding.py @@ -147,6 +147,18 @@ class MiscSourceEncodingTest(unittest.TestCase): self.assertTrue(c.exception.args[0].startswith(expected), msg=c.exception.args[0]) + def test_file_parse_error_multiline(self): + # gh96611: + with open(TESTFN, "wb") as fd: + fd.write(b'print("""\n\xb1""")\n') + + try: + retcode, stdout, stderr = script_helper.assert_python_failure(TESTFN) + + self.assertGreater(retcode, 0) + self.assertIn(b"Non-UTF-8 code starting with '\\xb1'", stderr) + finally: + os.unlink(TESTFN) class AbstractSourceEncodingTest: -- cgit v1.2.3