Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 1 | #! -*- coding: koi8-r -*-
|
Martin v. Löwis | f7e74b7 | 2004-10-13 05:29:39 +0000 | [diff] [blame] | 2 | # This file is marked as binary in the CVS, to prevent MacCVS from recoding it.
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 3 |
|
| 4 | import unittest
|
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 5 | from test import support
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 6 |
|
| 7 | class PEP263Test(unittest.TestCase):
|
| 8 |
|
| 9 | def test_pep263(self):
|
| 10 | self.assertEqual(
|
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 11 | "ðÉÔÏÎ".encode("utf-8"),
|
Thomas Heller | acb470c | 2007-07-11 19:34:54 +0000 | [diff] [blame] | 12 | b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd'
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 13 | )
|
| 14 | self.assertEqual(
|
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 15 | "\ð".encode("utf-8"),
|
Thomas Heller | acb470c | 2007-07-11 19:34:54 +0000 | [diff] [blame] | 16 | b'\\\xd0\x9f'
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 17 | )
|
| 18 |
|
Georg Brandl | 86def6c | 2008-01-21 20:36:10 +0000 | [diff] [blame] | 19 | def test_compilestring(self):
|
| 20 | # see #1882
|
Georg Brandl | 39b21ff | 2008-01-23 17:10:38 +0000 | [diff] [blame] | 21 | c = compile(b"\n# coding: utf-8\nu = '\xc3\xb3'\n", "dummy", "exec")
|
Georg Brandl | 86def6c | 2008-01-21 20:36:10 +0000 | [diff] [blame] | 22 | d = {}
|
| 23 | exec(c, d)
|
| 24 | self.assertEqual(d['u'], '\xf3')
|
| 25 |
|
Martin v. Löwis | 2593146 | 2008-03-17 20:43:42 +0000 | [diff] [blame] | 26 | 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 Brandl | 86def6c | 2008-01-21 20:36:10 +0000 | [diff] [blame] | 33 |
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 34 | def test_main():
|
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 35 | support.run_unittest(PEP263Test)
|
Raymond Hettinger | f9f4c69 | 2003-08-30 22:54:55 +0000 | [diff] [blame] | 36 |
|
| 37 | if __name__=="__main__":
|
| 38 | test_main()
|