/Lib/test/test_codecencodings_cn.py

http://unladen-swallow.googlecode.com/ · Python · 57 lines · 43 code · 6 blank · 8 comment · 1 complexity · ce0f9ee9355febc1e812fa6c9f66acdf MD5 · raw file

  1. #!/usr/bin/env python
  2. #
  3. # test_codecencodings_cn.py
  4. # Codec encoding tests for PRC encodings.
  5. #
  6. from test import test_support
  7. from test import test_multibytecodec_support
  8. import unittest
  9. class Test_GB2312(test_multibytecodec_support.TestBase, unittest.TestCase):
  10. encoding = 'gb2312'
  11. tstring = test_multibytecodec_support.load_teststring('gb2312')
  12. codectests = (
  13. # invalid bytes
  14. ("abc\x81\x81\xc1\xc4", "strict", None),
  15. ("abc\xc8", "strict", None),
  16. ("abc\x81\x81\xc1\xc4", "replace", u"abc\ufffd\u804a"),
  17. ("abc\x81\x81\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
  18. ("abc\x81\x81\xc1\xc4", "ignore", u"abc\u804a"),
  19. ("\xc1\x64", "strict", None),
  20. )
  21. class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase):
  22. encoding = 'gbk'
  23. tstring = test_multibytecodec_support.load_teststring('gbk')
  24. codectests = (
  25. # invalid bytes
  26. ("abc\x80\x80\xc1\xc4", "strict", None),
  27. ("abc\xc8", "strict", None),
  28. ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
  29. ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
  30. ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"),
  31. ("\x83\x34\x83\x31", "strict", None),
  32. (u"\u30fb", "strict", None),
  33. )
  34. class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase):
  35. encoding = 'gb18030'
  36. tstring = test_multibytecodec_support.load_teststring('gb18030')
  37. codectests = (
  38. # invalid bytes
  39. ("abc\x80\x80\xc1\xc4", "strict", None),
  40. ("abc\xc8", "strict", None),
  41. ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
  42. ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
  43. ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"),
  44. ("abc\x84\x39\x84\x39\xc1\xc4", "replace", u"abc\ufffd\u804a"),
  45. (u"\u30fb", "strict", "\x819\xa79"),
  46. )
  47. has_iso10646 = True
  48. def test_main():
  49. test_support.run_unittest(__name__)
  50. if __name__ == "__main__":
  51. test_main()