blob: 81d15bc8f40ce6a80643758dafdf4debfadee690 [file] [log] [blame]
Martin v. Löwis447d33e2007-07-29 18:10:01 +00001# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
2
3import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00004from test import support
Martin v. Löwis447d33e2007-07-29 18:10:01 +00005
6class 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:
22 self.assert_(str(msg).find("Non-UTF-8 code starting with") >= 0)
23 else:
24 self.fail("expected exception didn't occur")
25
Brett Cannonda780432008-10-17 03:38:50 +000026
27class 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
Martin v. Löwis447d33e2007-07-29 18:10:01 +000042def test_main():
Brett Cannonda780432008-10-17 03:38:50 +000043 support.run_unittest(PEP3120Test, BuiltinCompileTests)
Martin v. Löwis447d33e2007-07-29 18:10:01 +000044
45if __name__=="__main__":
46 test_main()