»Core Development>Code coverage>Lib/test/test_utf8source.py

Python code coverage for Lib/test/test_utf8source.py

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