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 |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 4 | |
| 5 | class PEP3120Test(unittest.TestCase): |
| 6 | |
| 7 | def test_pep3120(self): |
| 8 | self.assertEqual( |
| 9 | "Питон".encode("utf-8"), |
| 10 | b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' |
| 11 | ) |
| 12 | self.assertEqual( |
| 13 | "\П".encode("utf-8"), |
| 14 | b'\\\xd0\x9f' |
| 15 | ) |
| 16 | |
| 17 | def test_badsyntax(self): |
| 18 | try: |
| 19 | import test.badsyntax_pep3120 |
| 20 | except SyntaxError as msg: |
Victor Stinner | 5c724a8 | 2012-02-15 23:44:03 +0100 | [diff] [blame] | 21 | msg = str(msg).lower() |
| 22 | self.assertTrue('utf-8' in msg) |
Martin v. Löwis | 447d33e | 2007-07-29 18:10:01 +0000 | [diff] [blame] | 23 | else: |
| 24 | self.fail("expected exception didn't occur") |
| 25 | |
Brett Cannon | da78043 | 2008-10-17 03:38:50 +0000 | [diff] [blame] | 26 | |
| 27 | class BuiltinCompileTests(unittest.TestCase): |
| 28 | |
| 29 | # Issue 3574. |
| 30 | def test_latin1(self): |
| 31 | # Allow compile() to read Latin-1 source. |
| 32 | source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1") |
| 33 | try: |
| 34 | code = compile(source_code, '<dummy>', 'exec') |
| 35 | except SyntaxError: |
| 36 | self.fail("compile() cannot handle Latin-1 source") |
| 37 | ns = {} |
| 38 | exec(code, ns) |
| 39 | self.assertEqual('Ç', ns['u']) |
| 40 | |
| 41 | |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame^] | 42 | if __name__ == "__main__": |
| 43 | unittest.main() |