1import unittest 2 3class PEP3131Test(unittest.TestCase): 4 5 def test_valid(self): 6 class T: 7 ä = 1 8 µ = 2 # this is a compatibility character 9 蟒 = 3 10 x = 4 11 self.assertEqual(getattr(T, "\xe4"), 1) 12 self.assertEqual(getattr(T, "\u03bc"), 2) 13 self.assertEqual(getattr(T, '\u87d2'), 3) 14 self.assertEqual(getattr(T, 'x\U000E0100'), 4) 15 16 def test_non_bmp_normalized(self): 17 = 1 18 self.assertIn("Unicode", dir()) 19 20 def test_invalid(self): 21 try: 22 from test import badsyntax_3131 23 except SyntaxError as err: 24 self.assertEqual(str(err), 25 "invalid character '€' (U+20AC) (badsyntax_3131.py, line 2)") 26 self.assertEqual(err.lineno, 2) 27 self.assertEqual(err.offset, 1) 28 else: 29 self.fail("expected exception didn't occur") 30 31if __name__ == "__main__": 32 unittest.main() 33