Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 1 | # This file is marked as binary in the CVS, to prevent MacCVS from recoding it. |
| 2 | |
| 3 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 4 | from test import support |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 5 | |
| 6 | class PEP3120Test(unittest.TestCase): |
| 7 | |
| 8 | def test_pep3120(self): |
| 9 | self.assertEqual( |
| 10 | "Питон".encode("utf-8"), |
| 11 | b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' |
| 12 | ) |
| 13 | self.assertEqual( |
| 14 | "\П".encode("utf-8"), |
| 15 | b'\\\xd0\x9f' |
| 16 | ) |
| 17 | |
| 18 | def test_badsyntax(self): |
| 19 | try: |
| 20 | import test.badsyntax_pep3120 |
| 21 | except SyntaxError as msg: |
Marc-André Lemburg | 8f36af7 | 2011-02-25 15:42:01 +0000 | [diff] [blame] | 22 | msg = str(msg).lower() |
| 23 | self.assertTrue('utf-8' in msg or 'utf8' in msg) |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 24 | else: |
| 25 | self.fail("expected exception didn't occur") |
| 26 | |
Brett Cannon | da78043 | 2008-10-17 03:38:50 +0000 | [diff] [blame] | 27 | |
| 28 | class BuiltinCompileTests(unittest.TestCase): |
| 29 | |
| 30 | # Issue 3574. |
| 31 | def test_latin1(self): |
| 32 | # Allow compile() to read Latin-1 source. |
| 33 | source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1") |
| 34 | try: |
| 35 | code = compile(source_code, '<dummy>', 'exec') |
| 36 | except SyntaxError: |
| 37 | self.fail("compile() cannot handle Latin-1 source") |
| 38 | ns = {} |
| 39 | exec(code, ns) |
| 40 | self.assertEqual('Ç', ns['u']) |
| 41 | |
| 42 | |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 43 | def test_main(): |
Brett Cannon | da78043 | 2008-10-17 03:38:50 +0000 | [diff] [blame] | 44 | support.run_unittest(PEP3120Test, BuiltinCompileTests) |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 45 | |
| 46 | if __name__=="__main__": |
| 47 | test_main() |