diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-05 08:00:56 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-05 08:00:56 (GMT) |
commit | 607cb9cf99878e0965e43464652a0af8f5ef709a (patch) | |
tree | 217b869476e73ee40fd9dbaeb1a8d5f2b9e34113 | |
parent | d43ffc9aba8d3a594486d2488bf3e3dfb50a43b2 (diff) | |
download | cpython-607cb9cf99878e0965e43464652a0af8f5ef709a.zip cpython-607cb9cf99878e0965e43464652a0af8f5ef709a.tar.gz cpython-607cb9cf99878e0965e43464652a0af8f5ef709a.tar.bz2 |
Issue #22221: Add tests for compile() with source encoding cookie.
-rw-r--r-- | Lib/test/test_compile.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index b1f55bb..6116676 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -304,9 +304,26 @@ if 1: l = lambda: "foo" self.assertIsNone(l.__doc__) -## def test_unicode_encoding(self): -## code = "# -*- coding: utf-8 -*-\npass\n" -## self.assertRaises(SyntaxError, compile, code, "tmp", "exec") + def test_encoding(self): + code = b'# -*- coding: badencoding -*-\npass\n' + self.assertRaises(SyntaxError, compile, code, 'tmp', 'exec') + code = '# -*- coding: badencoding -*-\n"\xc2\xa4"\n' + compile(code, 'tmp', 'exec') + self.assertEqual(eval(code), '\xc2\xa4') + code = '"\xc2\xa4"\n' + self.assertEqual(eval(code), '\xc2\xa4') + code = b'"\xc2\xa4"\n' + self.assertEqual(eval(code), '\xa4') + code = b'# -*- coding: latin1 -*-\n"\xc2\xa4"\n' + self.assertEqual(eval(code), '\xc2\xa4') + code = b'# -*- coding: utf-8 -*-\n"\xc2\xa4"\n' + self.assertEqual(eval(code), '\xa4') + code = b'# -*- coding: iso8859-15 -*-\n"\xc2\xa4"\n' + self.assertEqual(eval(code), '\xc2\u20ac') + code = '"""\\\n# -*- coding: iso8859-15 -*-\n\xc2\xa4"""\n' + self.assertEqual(eval(code), '# -*- coding: iso8859-15 -*-\n\xc2\xa4') + code = b'"""\\\n# -*- coding: iso8859-15 -*-\n\xc2\xa4"""\n' + self.assertEqual(eval(code), '# -*- coding: iso8859-15 -*-\n\xa4') def test_subscripts(self): # SF bug 1448804 |