0001 #!/usr/bin/env python 0002 # 0003 # test_codecencodings_jp.py 0004 # Codec encoding tests for Japanese encodings. 0005 # 0006 # $CJKCodecs: test_codecencodings_jp.py,v 1.3 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_CP932(test_multibytecodec_support.TestBase, unittest.TestCase): 0013 encoding = 'cp932' 0014 tstring = test_multibytecodec_support.load_teststring('shift_jis') 0015 codectests = ( 0016 # invalid bytes 0017 ("abc\x81\x00\x81\x00\x82\x84", "strict", None), 0018 ("abc\xf8", "strict", None), 0019 ("abc\x81\x00\x82\x84", "replace", u"abc\ufffd\uff44"), 0020 ("abc\x81\x00\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"), 0021 ("abc\x81\x00\x82\x84", "ignore", u"abc\uff44"), 0022 # sjis vs cp932 0023 ("\\\x7e", "replace", u"\\\x7e"), 0024 ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\uff3c\u2225\uff0d"), 0025 ) 0026 0027 class Test_EUC_JISX0213(test_multibytecodec_support.TestBase, 0028 unittest.TestCase): 0029 encoding = 'euc_jisx0213' 0030 tstring = test_multibytecodec_support.load_teststring('euc_jisx0213') 0031 codectests = ( 0032 # invalid bytes 0033 ("abc\x80\x80\xc1\xc4", "strict", None), 0034 ("abc\xc8", "strict", None), 0035 ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"), 0036 ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"), 0037 ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u7956"), 0038 ("abc\x8f\x83\x83", "replace", u"abc\ufffd"), 0039 ("\xc1\x64", "strict", None), 0040 ("\xa1\xc0", "strict", u"\uff3c"), 0041 ) 0042 xmlcharnametest = ( 0043 u"\xab\u211c\xbb = \u2329\u1234\u232a", 0044 "\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" 0045 ) 0046 0047 eucjp_commontests = ( 0048 ("abc\x80\x80\xc1\xc4", "strict", None), 0049 ("abc\xc8", "strict", None), 0050 ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"), 0051 ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"), 0052 ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u7956"), 0053 ("abc\x8f\x83\x83", "replace", u"abc\ufffd"), 0054 ("\xc1\x64", "strict", None), 0055 ) 0056 0057 class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase, 0058 unittest.TestCase): 0059 encoding = 'euc_jp' 0060 tstring = test_multibytecodec_support.load_teststring('euc_jp') 0061 codectests = eucjp_commontests + ( 0062 ("\xa1\xc0\\", "strict", u"\uff3c\\"), 0063 (u"\xa5", "strict", "\x5c"), 0064 (u"\u203e", "strict", "\x7e"), 0065 ) 0066 0067 shiftjis_commonenctests = ( 0068 ("abc\x80\x80\x82\x84", "strict", None), 0069 ("abc\xf8", "strict", None), 0070 ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"), 0071 ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"), 0072 ("abc\x80\x80\x82\x84def", "ignore", u"abc\uff44def"), 0073 ) 0074 0075 class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase): 0076 encoding = 'shift_jis' 0077 tstring = test_multibytecodec_support.load_teststring('shift_jis') 0078 codectests = shiftjis_commonenctests + ( 0079 ("\\\x7e", "strict", u"\\\x7e"), 0080 ("\x81\x5f\x81\x61\x81\x7c", "strict", u"\uff3c\u2016\u2212"), 0081 ) 0082 0083 class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase): 0084 encoding = 'shift_jisx0213' 0085 tstring = test_multibytecodec_support.load_teststring('shift_jisx0213') 0086 codectests = ( 0087 # invalid bytes 0088 ("abc\x80\x80\x82\x84", "strict", None), 0089 ("abc\xf8", "strict", None), 0090 ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"), 0091 ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"), 0092 ("abc\x80\x80\x82\x84def", "ignore", u"abc\uff44def"), 0093 # sjis vs cp932 0094 ("\\\x7e", "replace", u"\xa5\u203e"), 0095 ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\x5c\u2016\u2212"), 0096 ) 0097 xmlcharnametest = ( 0098 u"\xab\u211c\xbb = \u2329\u1234\u232a", 0099 "\x85Gℜ\x85Q = ⟨ሴ⟩" 0100 ) 0101 0102 def test_main(): 0103 suite = unittest.TestSuite() 0104 suite.addTest(unittest.makeSuite(Test_CP932)) 0105 suite.addTest(unittest.makeSuite(Test_EUC_JISX0213)) 0106 suite.addTest(unittest.makeSuite(Test_EUC_JP_COMPAT)) 0107 suite.addTest(unittest.makeSuite(Test_SJIS_COMPAT)) 0108 suite.addTest(unittest.makeSuite(Test_SJISX0213)) 0109 test_support.run_suite(suite) 0110 0111 if __name__ == "__main__": 0112 test_main() 0113
Generated by PyXR 0.9.4