Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 1 | import unittest |
Benjamin Peterson | be66287 | 2011-08-12 23:35:34 -0500 | [diff] [blame] | 2 | import sys |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 3 | from test import support |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 4 | |
| 5 | class PEP3131Test(unittest.TestCase): |
| 6 | |
| 7 | def test_valid(self): |
| 8 | class T: |
| 9 | ä = 1 |
| 10 | µ = 2 # this is a compatibility character |
| 11 | 蟒 = 3 |
Benjamin Peterson | be66287 | 2011-08-12 23:35:34 -0500 | [diff] [blame] | 12 | x󠄀 = 4 |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 13 | self.assertEqual(getattr(T, "\xe4"), 1) |
| 14 | self.assertEqual(getattr(T, "\u03bc"), 2) |
| 15 | self.assertEqual(getattr(T, '\u87d2'), 3) |
Benjamin Peterson | be66287 | 2011-08-12 23:35:34 -0500 | [diff] [blame] | 16 | self.assertEqual(getattr(T, 'x\U000E0100'), 4) |
| 17 | |
| 18 | def test_non_bmp_normalized(self): |
| 19 | 𝔘𝔫𝔦𝔠𝔬𝔡𝔢 = 1 |
Martin v. Löwis | ff1ef07 | 2011-09-29 13:49:10 +0200 | [diff] [blame] | 20 | self.assertIn("Unicode", dir()) |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 21 | |
| 22 | def test_invalid(self): |
| 23 | try: |
| 24 | from test import badsyntax_3131 |
| 25 | except SyntaxError as s: |
Ezio Melotti | b3aedd4 | 2010-11-20 19:04:17 +0000 | [diff] [blame] | 26 | self.assertEqual(str(s), |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 27 | "invalid character in identifier (badsyntax_3131.py, line 2)") |
| 28 | else: |
| 29 | self.fail("expected exception didn't occur") |
| 30 | |
| 31 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 32 | support.run_unittest(PEP3131Test) |
Martin v. Löwis | 4738340 | 2007-08-15 07:32:56 +0000 | [diff] [blame] | 33 | |
| 34 | if __name__=="__main__": |
| 35 | test_main() |