2007-07-30 02:10:01 +08:00
|
|
|
# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
|
|
|
|
|
|
|
|
import unittest
|
2008-05-21 05:35:26 +08:00
|
|
|
from test import support
|
2007-07-30 02:10:01 +08:00
|
|
|
|
|
|
|
class PEP3120Test(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_pep3120(self):
|
|
|
|
self.assertEqual(
|
|
|
|
"Питон".encode("utf-8"),
|
|
|
|
b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
"\П".encode("utf-8"),
|
|
|
|
b'\\\xd0\x9f'
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_badsyntax(self):
|
|
|
|
try:
|
|
|
|
import test.badsyntax_pep3120
|
|
|
|
except SyntaxError as msg:
|
2009-08-31 04:07:38 +08:00
|
|
|
msg = str(msg)
|
|
|
|
self.assertTrue('UTF-8' in msg or 'utf8' in msg)
|
2007-07-30 02:10:01 +08:00
|
|
|
else:
|
|
|
|
self.fail("expected exception didn't occur")
|
|
|
|
|
2008-10-17 11:38:50 +08:00
|
|
|
|
|
|
|
class BuiltinCompileTests(unittest.TestCase):
|
|
|
|
|
|
|
|
# Issue 3574.
|
|
|
|
def test_latin1(self):
|
|
|
|
# Allow compile() to read Latin-1 source.
|
|
|
|
source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1")
|
|
|
|
try:
|
|
|
|
code = compile(source_code, '<dummy>', 'exec')
|
|
|
|
except SyntaxError:
|
|
|
|
self.fail("compile() cannot handle Latin-1 source")
|
|
|
|
ns = {}
|
|
|
|
exec(code, ns)
|
|
|
|
self.assertEqual('Ç', ns['u'])
|
|
|
|
|
|
|
|
|
2007-07-30 02:10:01 +08:00
|
|
|
def test_main():
|
2008-10-17 11:38:50 +08:00
|
|
|
support.run_unittest(PEP3120Test, BuiltinCompileTests)
|
2007-07-30 02:10:01 +08:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
test_main()
|