test_utf8source.py 1.1 KB

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