1 | n/a | # This file is marked as binary in the CVS, to prevent MacCVS from recoding it. |
---|
2 | n/a | |
---|
3 | n/a | import unittest |
---|
4 | n/a | |
---|
5 | n/a | class PEP3120Test(unittest.TestCase): |
---|
6 | n/a | |
---|
7 | n/a | def test_pep3120(self): |
---|
8 | n/a | self.assertEqual( |
---|
9 | n/a | "ÐиÑон".encode("utf-8"), |
---|
10 | n/a | b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd' |
---|
11 | n/a | ) |
---|
12 | n/a | self.assertEqual( |
---|
13 | n/a | "\Ð".encode("utf-8"), |
---|
14 | n/a | b'\\\xd0\x9f' |
---|
15 | n/a | ) |
---|
16 | n/a | |
---|
17 | n/a | def test_badsyntax(self): |
---|
18 | n/a | try: |
---|
19 | n/a | import test.badsyntax_pep3120 |
---|
20 | n/a | except SyntaxError as msg: |
---|
21 | n/a | msg = str(msg).lower() |
---|
22 | n/a | self.assertTrue('utf-8' in msg) |
---|
23 | n/a | else: |
---|
24 | n/a | self.fail("expected exception didn't occur") |
---|
25 | n/a | |
---|
26 | n/a | |
---|
27 | n/a | class BuiltinCompileTests(unittest.TestCase): |
---|
28 | n/a | |
---|
29 | n/a | # Issue 3574. |
---|
30 | n/a | def test_latin1(self): |
---|
31 | n/a | # Allow compile() to read Latin-1 source. |
---|
32 | n/a | source_code = '# coding: Latin-1\nu = "Ã"\n'.encode("Latin-1") |
---|
33 | n/a | try: |
---|
34 | n/a | code = compile(source_code, '<dummy>', 'exec') |
---|
35 | n/a | except SyntaxError: |
---|
36 | n/a | self.fail("compile() cannot handle Latin-1 source") |
---|
37 | n/a | ns = {} |
---|
38 | n/a | exec(code, ns) |
---|
39 | n/a | self.assertEqual('Ã', ns['u']) |
---|
40 | n/a | |
---|
41 | n/a | |
---|
42 | n/a | if __name__ == "__main__": |
---|
43 | n/a | unittest.main() |
---|