From 1faa3cd1a18db857f6aafcac3c026dfe9a7b512e Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 22 Apr 2021 22:26:30 -0400 Subject: [PATCH 1/2] Add test_utf8source from CPython 3.8 --- Lib/test/test_utf8source.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Lib/test/test_utf8source.py diff --git a/Lib/test/test_utf8source.py b/Lib/test/test_utf8source.py new file mode 100644 index 000000000..97dced8a6 --- /dev/null +++ b/Lib/test/test_utf8source.py @@ -0,0 +1,43 @@ +# This file is marked as binary in the CVS, to prevent MacCVS from recoding it. + +import unittest + +class PEP3120Test(unittest.TestCase): + + def test_pep3120(self): + self.assertEqual( + "Питон".encode("utf-8"), + b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' + ) + self.assertEqual( + "\П".encode("utf-8"), + b'\\\xd0\x9f' + ) + + def test_badsyntax(self): + try: + import test.badsyntax_pep3120 + except SyntaxError as msg: + msg = str(msg).lower() + self.assertTrue('utf-8' in msg) + else: + self.fail("expected exception didn't occur") + + +class BuiltinCompileTests(unittest.TestCase): + + # Issue 3574. + def test_latin1(self): + # Allow compile() to read Latin-1 source. + source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1") + try: + code = compile(source_code, '', 'exec') + except SyntaxError: + self.fail("compile() cannot handle Latin-1 source") + ns = {} + exec(code, ns) + self.assertEqual('Ç', ns['u']) + + +if __name__ == "__main__": + unittest.main() From deac676ff2463b8b140122372084650524f95e7d Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 22 Apr 2021 22:28:24 -0400 Subject: [PATCH 2/2] Mark erroring tests --- Lib/test/test_utf8source.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/test/test_utf8source.py b/Lib/test/test_utf8source.py index 97dced8a6..e2f745c25 100644 --- a/Lib/test/test_utf8source.py +++ b/Lib/test/test_utf8source.py @@ -14,6 +14,8 @@ class PEP3120Test(unittest.TestCase): b'\\\xd0\x9f' ) + # TODO: RUSTPYTHON + @unittest.expectedFailure # "badsyntax_pep3120.py" may make the WASM CI fail def test_badsyntax(self): try: import test.badsyntax_pep3120 @@ -26,6 +28,8 @@ class PEP3120Test(unittest.TestCase): class BuiltinCompileTests(unittest.TestCase): + # TODO: RUSTPYTHON + @unittest.expectedFailure # Issue 3574. def test_latin1(self): # Allow compile() to read Latin-1 source.