PyXR

c:\python24\lib \ test \ test_codecencodings_cn.py



0001 #!/usr/bin/env python
0002 #
0003 # test_codecencodings_cn.py
0004 #   Codec encoding tests for PRC encodings.
0005 #
0006 # $CJKCodecs: test_codecencodings_cn.py,v 1.2 2004/06/19 06:09:55 perky Exp $
0007 
0008 from test import test_support
0009 from test import test_multibytecodec_support
0010 import unittest
0011 
0012 class Test_GB2312(test_multibytecodec_support.TestBase, unittest.TestCase):
0013     encoding = 'gb2312'
0014     tstring = test_multibytecodec_support.load_teststring('gb2312')
0015     codectests = (
0016         # invalid bytes
0017         ("abc\x81\x81\xc1\xc4", "strict",  None),
0018         ("abc\xc8", "strict",  None),
0019         ("abc\x81\x81\xc1\xc4", "replace", u"abc\ufffd\u804a"),
0020         ("abc\x81\x81\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
0021         ("abc\x81\x81\xc1\xc4", "ignore",  u"abc\u804a"),
0022         ("\xc1\x64", "strict", None),
0023     )
0024 
0025 class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase):
0026     encoding = 'gbk'
0027     tstring = test_multibytecodec_support.load_teststring('gbk')
0028     codectests = (
0029         # invalid bytes
0030         ("abc\x80\x80\xc1\xc4", "strict",  None),
0031         ("abc\xc8", "strict",  None),
0032         ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
0033         ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
0034         ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\u804a"),
0035         ("\x83\x34\x83\x31", "strict", None),
0036     )
0037 
0038 class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase):
0039     encoding = 'gb18030'
0040     tstring = test_multibytecodec_support.load_teststring('gb18030')
0041     codectests = (
0042         # invalid bytes
0043         ("abc\x80\x80\xc1\xc4", "strict",  None),
0044         ("abc\xc8", "strict",  None),
0045         ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),
0046         ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),
0047         ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\u804a"),
0048         ("abc\x84\x39\x84\x39\xc1\xc4", "replace", u"abc\ufffd\u804a"),
0049     )
0050     has_iso10646 = True
0051 
0052 def test_main():
0053     suite = unittest.TestSuite()
0054     suite.addTest(unittest.makeSuite(Test_GB2312))
0055     suite.addTest(unittest.makeSuite(Test_GBK))
0056     suite.addTest(unittest.makeSuite(Test_GB18030))
0057     test_support.run_suite(suite)
0058 
0059 if __name__ == "__main__":
0060     test_main()
0061 

Generated by PyXR 0.9.4
SourceForge.net Logo