test_unichr.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. __author__ = 'jsd'
  2. # Test the unichr() function
  3. # This is hardly an exhaustive check,
  4. # but spot-checking is better than no checking.
  5. import unittest
  6. class TestUnichr(unittest.TestCase):
  7. # one-byte code (basic plane):
  8. def testOne(self):
  9. self.assertEqual(unichr(0x61), 'a')
  10. def testOneMore(self):
  11. self.assertEqual(unichr(0x61), u'a')
  12. # two-byte code:
  13. def testTwo(self):
  14. self.assertEqual(unichr(0x3c9), u'ω')
  15. # three-byte code:
  16. def testThree(self):
  17. self.assertEqual(unichr(0x2207), u'∇')
  18. # four-byte code (astral plane)
  19. def testFour(self):
  20. self.assertEqual(unichr(0x1d11e), u'𝄞')
  21. def testFive(self):
  22. ex = 0
  23. try:
  24. s1 = unichr(-1) # should throw ValueError
  25. except ValueError:
  26. ex = 1
  27. self.assertEqual(1, ex)
  28. def testSix(self):
  29. ex = 0
  30. try:
  31. s1 = unichr(1<<22) # should throw ValueError
  32. except ValueError:
  33. ex = 1
  34. self.assertEqual(1, ex)
  35. if __name__ == '__main__':
  36. unittest.main()