blob: 17abbd807a01cd3a0a7c6bef8cff54b269aadab3 [file] [log] [blame]
Raymond Hettingerf9f4c692003-08-30 22:54:55 +00001#! -*- coding: koi8-r -*-
Martin v. Löwisf7e74b72004-10-13 05:29:39 +00002# This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
Raymond Hettingerf9f4c692003-08-30 22:54:55 +00003
4import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +00005from test import support
Raymond Hettingerf9f4c692003-08-30 22:54:55 +00006
7class PEP263Test(unittest.TestCase):
8
9 def test_pep263(self):
10 self.assertEqual(
Guido van Rossumef87d6e2007-05-02 19:09:54 +000011 "ðÉÔÏÎ".encode("utf-8"),
Thomas Helleracb470c2007-07-11 19:34:54 +000012 b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
Raymond Hettingerf9f4c692003-08-30 22:54:55 +000013 )
14 self.assertEqual(
Guido van Rossumef87d6e2007-05-02 19:09:54 +000015 "\ð".encode("utf-8"),
Thomas Helleracb470c2007-07-11 19:34:54 +000016 b'\\\xd0\x9f'
Raymond Hettingerf9f4c692003-08-30 22:54:55 +000017 )
18
Georg Brandl86def6c2008-01-21 20:36:10 +000019 def test_compilestring(self):
20 # see #1882
Georg Brandl39b21ff2008-01-23 17:10:38 +000021 c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec")
Georg Brandl86def6c2008-01-21 20:36:10 +000022 d = {}
23 exec(c, d)
24 self.assertEqual(d['u'], '\xf3')
25
Martin v. Löwis25931462008-03-17 20:43:42 +000026 def test_issue2301(self):
27 try:
28 compile(b"# coding: cp932\nprint '\x94\x4e'", "dummy", "exec")
29 except SyntaxError as v:
30 self.assertEquals(v.text, "print '\u5e74'")
31 else:
32 self.fail()
Georg Brandl86def6c2008-01-21 20:36:10 +000033
Raymond Hettingerf9f4c692003-08-30 22:54:55 +000034def test_main():
Benjamin Petersonee8712c2008-05-20 21:35:26 +000035 support.run_unittest(PEP263Test)
Raymond Hettingerf9f4c692003-08-30 22:54:55 +000036
37if __name__=="__main__":
38 test_main()