3 # test_codecencodings_jp.py
4 # Codec encoding tests for Japanese encodings.
7 from test
import test_support
8 from test
import test_multibytecodec_support
11 class Test_CP932(test_multibytecodec_support
.TestBase
, unittest
.TestCase
):
13 tstring
= test_multibytecodec_support
.load_teststring('shift_jis')
16 ("abc\x81\x00\x81\x00\x82\x84", "strict", None),
17 ("abc\xf8", "strict", None),
18 ("abc\x81\x00\x82\x84", "replace", u
"abc\ufffd\uff44"),
19 ("abc\x81\x00\x82\x84\x88", "replace", u
"abc\ufffd\uff44\ufffd"),
20 ("abc\x81\x00\x82\x84", "ignore", u
"abc\uff44"),
22 ("\\\x7e", "replace", u
"\\\x7e"),
23 ("\x81\x5f\x81\x61\x81\x7c", "replace", u
"\uff3c\u2225\uff0d"),
26 class Test_EUC_JISX0213(test_multibytecodec_support
.TestBase
,
28 encoding
= 'euc_jisx0213'
29 tstring
= test_multibytecodec_support
.load_teststring('euc_jisx0213')
32 ("abc\x80\x80\xc1\xc4", "strict", None),
33 ("abc\xc8", "strict", None),
34 ("abc\x80\x80\xc1\xc4", "replace", u
"abc\ufffd\u7956"),
35 ("abc\x80\x80\xc1\xc4\xc8", "replace", u
"abc\ufffd\u7956\ufffd"),
36 ("abc\x80\x80\xc1\xc4", "ignore", u
"abc\u7956"),
37 ("abc\x8f\x83\x83", "replace", u
"abc\ufffd"),
38 ("\xc1\x64", "strict", None),
39 ("\xa1\xc0", "strict", u
"\uff3c"),
42 u
"\xab\u211c\xbb = \u2329\u1234\u232a",
43 "\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
47 ("abc\x80\x80\xc1\xc4", "strict", None),
48 ("abc\xc8", "strict", None),
49 ("abc\x80\x80\xc1\xc4", "replace", u
"abc\ufffd\u7956"),
50 ("abc\x80\x80\xc1\xc4\xc8", "replace", u
"abc\ufffd\u7956\ufffd"),
51 ("abc\x80\x80\xc1\xc4", "ignore", u
"abc\u7956"),
52 ("abc\x8f\x83\x83", "replace", u
"abc\ufffd"),
53 ("\xc1\x64", "strict", None),
56 class Test_EUC_JP_COMPAT(test_multibytecodec_support
.TestBase
,
59 tstring
= test_multibytecodec_support
.load_teststring('euc_jp')
60 codectests
= eucjp_commontests
+ (
61 ("\xa1\xc0\\", "strict", u
"\uff3c\\"),
62 (u
"\xa5", "strict", "\x5c"),
63 (u
"\u203e", "strict", "\x7e"),
66 shiftjis_commonenctests
= (
67 ("abc\x80\x80\x82\x84", "strict", None),
68 ("abc\xf8", "strict", None),
69 ("abc\x80\x80\x82\x84", "replace", u
"abc\ufffd\uff44"),
70 ("abc\x80\x80\x82\x84\x88", "replace", u
"abc\ufffd\uff44\ufffd"),
71 ("abc\x80\x80\x82\x84def", "ignore", u
"abc\uff44def"),
74 class Test_SJIS_COMPAT(test_multibytecodec_support
.TestBase
, unittest
.TestCase
):
75 encoding
= 'shift_jis'
76 tstring
= test_multibytecodec_support
.load_teststring('shift_jis')
77 codectests
= shiftjis_commonenctests
+ (
78 ("\\\x7e", "strict", u
"\\\x7e"),
79 ("\x81\x5f\x81\x61\x81\x7c", "strict", u
"\uff3c\u2016\u2212"),
82 class Test_SJISX0213(test_multibytecodec_support
.TestBase
, unittest
.TestCase
):
83 encoding
= 'shift_jisx0213'
84 tstring
= test_multibytecodec_support
.load_teststring('shift_jisx0213')
87 ("abc\x80\x80\x82\x84", "strict", None),
88 ("abc\xf8", "strict", None),
89 ("abc\x80\x80\x82\x84", "replace", u
"abc\ufffd\uff44"),
90 ("abc\x80\x80\x82\x84\x88", "replace", u
"abc\ufffd\uff44\ufffd"),
91 ("abc\x80\x80\x82\x84def", "ignore", u
"abc\uff44def"),
93 ("\\\x7e", "replace", u
"\xa5\u203e"),
94 ("\x81\x5f\x81\x61\x81\x7c", "replace", u
"\x5c\u2016\u2212"),
97 u
"\xab\u211c\xbb = \u2329\u1234\u232a",
98 "\x85Gℜ\x85Q = ⟨ሴ⟩"
102 test_support
.run_unittest(__name__
)
104 if __name__
== "__main__":