(root)/
Python-3.11.7/
Lib/
test/
test_utf8source.py
       1  import unittest
       2  
       3  class ESC[4;38;5;81mPEP3120Test(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
       4  
       5      def test_pep3120(self):
       6          self.assertEqual(
       7              "Питон".encode("utf-8"),
       8              b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
       9          )
      10          self.assertEqual(
      11              "".encode("utf-8"),
      12              b'\\\xd0\x9f'
      13          )
      14  
      15      def test_badsyntax(self):
      16          try:
      17              import test.tokenizedata.badsyntax_pep3120
      18          except SyntaxError as msg:
      19              msg = str(msg).lower()
      20              self.assertTrue('utf-8' in msg)
      21          else:
      22              self.fail("expected exception didn't occur")
      23  
      24  
      25  class ESC[4;38;5;81mBuiltinCompileTests(ESC[4;38;5;149munittestESC[4;38;5;149m.ESC[4;38;5;149mTestCase):
      26  
      27      # Issue 3574.
      28      def test_latin1(self):
      29          # Allow compile() to read Latin-1 source.
      30          source_code = '# coding: Latin-1\nu = "Ç"\n'.encode("Latin-1")
      31          try:
      32              code = compile(source_code, '<dummy>', 'exec')
      33          except SyntaxError:
      34              self.fail("compile() cannot handle Latin-1 source")
      35          ns = {}
      36          exec(code, ns)
      37          self.assertEqual('Ç', ns['u'])
      38  
      39  
      40  if __name__ == "__main__":
      41      unittest.main()