]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | #!/usr/bin/env python\r |
2 | #\r | |
3 | # test_codecencodings_jp.py\r | |
4 | # Codec encoding tests for Japanese encodings.\r | |
5 | #\r | |
6 | \r | |
7 | from test import test_support\r | |
8 | from test import test_multibytecodec_support\r | |
9 | import unittest\r | |
10 | \r | |
11 | class Test_CP932(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
12 | encoding = 'cp932'\r | |
13 | tstring = test_multibytecodec_support.load_teststring('shift_jis')\r | |
14 | codectests = (\r | |
15 | # invalid bytes\r | |
16 | ("abc\x81\x00\x81\x00\x82\x84", "strict", None),\r | |
17 | ("abc\xf8", "strict", None),\r | |
18 | ("abc\x81\x00\x82\x84", "replace", u"abc\ufffd\uff44"),\r | |
19 | ("abc\x81\x00\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),\r | |
20 | ("abc\x81\x00\x82\x84", "ignore", u"abc\uff44"),\r | |
21 | # sjis vs cp932\r | |
22 | ("\\\x7e", "replace", u"\\\x7e"),\r | |
23 | ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\uff3c\u2225\uff0d"),\r | |
24 | )\r | |
25 | \r | |
26 | class Test_EUC_JISX0213(test_multibytecodec_support.TestBase,\r | |
27 | unittest.TestCase):\r | |
28 | encoding = 'euc_jisx0213'\r | |
29 | tstring = test_multibytecodec_support.load_teststring('euc_jisx0213')\r | |
30 | codectests = (\r | |
31 | # invalid bytes\r | |
32 | ("abc\x80\x80\xc1\xc4", "strict", None),\r | |
33 | ("abc\xc8", "strict", None),\r | |
34 | ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"),\r | |
35 | ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"),\r | |
36 | ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u7956"),\r | |
37 | ("abc\x8f\x83\x83", "replace", u"abc\ufffd"),\r | |
38 | ("\xc1\x64", "strict", None),\r | |
39 | ("\xa1\xc0", "strict", u"\uff3c"),\r | |
40 | )\r | |
41 | xmlcharnametest = (\r | |
42 | u"\xab\u211c\xbb = \u2329\u1234\u232a",\r | |
43 | "\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"\r | |
44 | )\r | |
45 | \r | |
46 | eucjp_commontests = (\r | |
47 | ("abc\x80\x80\xc1\xc4", "strict", None),\r | |
48 | ("abc\xc8", "strict", None),\r | |
49 | ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"),\r | |
50 | ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"),\r | |
51 | ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u7956"),\r | |
52 | ("abc\x8f\x83\x83", "replace", u"abc\ufffd"),\r | |
53 | ("\xc1\x64", "strict", None),\r | |
54 | )\r | |
55 | \r | |
56 | class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase,\r | |
57 | unittest.TestCase):\r | |
58 | encoding = 'euc_jp'\r | |
59 | tstring = test_multibytecodec_support.load_teststring('euc_jp')\r | |
60 | codectests = eucjp_commontests + (\r | |
61 | ("\xa1\xc0\\", "strict", u"\uff3c\\"),\r | |
62 | (u"\xa5", "strict", "\x5c"),\r | |
63 | (u"\u203e", "strict", "\x7e"),\r | |
64 | )\r | |
65 | \r | |
66 | shiftjis_commonenctests = (\r | |
67 | ("abc\x80\x80\x82\x84", "strict", None),\r | |
68 | ("abc\xf8", "strict", None),\r | |
69 | ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"),\r | |
70 | ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),\r | |
71 | ("abc\x80\x80\x82\x84def", "ignore", u"abc\uff44def"),\r | |
72 | )\r | |
73 | \r | |
74 | class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
75 | encoding = 'shift_jis'\r | |
76 | tstring = test_multibytecodec_support.load_teststring('shift_jis')\r | |
77 | codectests = shiftjis_commonenctests + (\r | |
78 | ("\\\x7e", "strict", u"\\\x7e"),\r | |
79 | ("\x81\x5f\x81\x61\x81\x7c", "strict", u"\uff3c\u2016\u2212"),\r | |
80 | )\r | |
81 | \r | |
82 | class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
83 | encoding = 'shift_jisx0213'\r | |
84 | tstring = test_multibytecodec_support.load_teststring('shift_jisx0213')\r | |
85 | codectests = (\r | |
86 | # invalid bytes\r | |
87 | ("abc\x80\x80\x82\x84", "strict", None),\r | |
88 | ("abc\xf8", "strict", None),\r | |
89 | ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"),\r | |
90 | ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),\r | |
91 | ("abc\x80\x80\x82\x84def", "ignore", u"abc\uff44def"),\r | |
92 | # sjis vs cp932\r | |
93 | ("\\\x7e", "replace", u"\xa5\u203e"),\r | |
94 | ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\x5c\u2016\u2212"),\r | |
95 | )\r | |
96 | xmlcharnametest = (\r | |
97 | u"\xab\u211c\xbb = \u2329\u1234\u232a",\r | |
98 | "\x85Gℜ\x85Q = ⟨ሴ⟩"\r | |
99 | )\r | |
100 | \r | |
101 | def test_main():\r | |
102 | test_support.run_unittest(__name__)\r | |
103 | \r | |
104 | if __name__ == "__main__":\r | |
105 | test_main()\r |