ยปCore Development>Code coverage>Lib/test/test_codecencodings_jp.py

Python code coverage for Lib/test/test_codecencodings_jp.py

#countcontent
1n/a#
2n/a# test_codecencodings_jp.py
3n/a# Codec encoding tests for Japanese encodings.
4n/a#
5n/a
6n/afrom test import multibytecodec_support
7n/aimport unittest
8n/a
9n/aclass Test_CP932(multibytecodec_support.TestBase, unittest.TestCase):
10n/a encoding = 'cp932'
11n/a tstring = multibytecodec_support.load_teststring('shift_jis')
12n/a codectests = (
13n/a # invalid bytes
14n/a (b"abc\x81\x00\x81\x00\x82\x84", "strict", None),
15n/a (b"abc\xf8", "strict", None),
16n/a (b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\x00\uff44"),
17n/a (b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\x00\uff44\ufffd"),
18n/a (b"abc\x81\x00\x82\x84", "ignore", "abc\x00\uff44"),
19n/a (b"ab\xEBxy", "replace", "ab\uFFFDxy"),
20n/a (b"ab\xF0\x39xy", "replace", "ab\uFFFD9xy"),
21n/a (b"ab\xEA\xF0xy", "replace", 'ab\ufffd\ue038y'),
22n/a # sjis vs cp932
23n/a (b"\\\x7e", "replace", "\\\x7e"),
24n/a (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"),
25n/a )
26n/a
27n/aeuc_commontests = (
28n/a # invalid bytes
29n/a (b"abc\x80\x80\xc1\xc4", "strict", None),
30n/a (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u7956"),
31n/a (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u7956\ufffd"),
32n/a (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"),
33n/a (b"abc\xc8", "strict", None),
34n/a (b"abc\x8f\x83\x83", "replace", "abc\ufffd\ufffd\ufffd"),
35n/a (b"\x82\xFCxy", "replace", "\ufffd\ufffdxy"),
36n/a (b"\xc1\x64", "strict", None),
37n/a (b"\xa1\xc0", "strict", "\uff3c"),
38n/a (b"\xa1\xc0\\", "strict", "\uff3c\\"),
39n/a (b"\x8eXY", "replace", "\ufffdXY"),
40n/a)
41n/a
42n/aclass Test_EUC_JIS_2004(multibytecodec_support.TestBase,
43n/a unittest.TestCase):
44n/a encoding = 'euc_jis_2004'
45n/a tstring = multibytecodec_support.load_teststring('euc_jisx0213')
46n/a codectests = euc_commontests
47n/a xmlcharnametest = (
48n/a "\xab\u211c\xbb = \u2329\u1234\u232a",
49n/a b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
50n/a )
51n/a
52n/aclass Test_EUC_JISX0213(multibytecodec_support.TestBase,
53n/a unittest.TestCase):
54n/a encoding = 'euc_jisx0213'
55n/a tstring = multibytecodec_support.load_teststring('euc_jisx0213')
56n/a codectests = euc_commontests
57n/a xmlcharnametest = (
58n/a "\xab\u211c\xbb = \u2329\u1234\u232a",
59n/a b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
60n/a )
61n/a
62n/aclass Test_EUC_JP_COMPAT(multibytecodec_support.TestBase,
63n/a unittest.TestCase):
64n/a encoding = 'euc_jp'
65n/a tstring = multibytecodec_support.load_teststring('euc_jp')
66n/a codectests = euc_commontests + (
67n/a ("\xa5", "strict", b"\x5c"),
68n/a ("\u203e", "strict", b"\x7e"),
69n/a )
70n/a
71n/ashiftjis_commonenctests = (
72n/a (b"abc\x80\x80\x82\x84", "strict", None),
73n/a (b"abc\xf8", "strict", None),
74n/a (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"),
75n/a)
76n/a
77n/aclass Test_SJIS_COMPAT(multibytecodec_support.TestBase, unittest.TestCase):
78n/a encoding = 'shift_jis'
79n/a tstring = multibytecodec_support.load_teststring('shift_jis')
80n/a codectests = shiftjis_commonenctests + (
81n/a (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"),
82n/a (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"),
83n/a
84n/a (b"\\\x7e", "strict", "\\\x7e"),
85n/a (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"),
86n/a (b"abc\x81\x39", "replace", "abc\ufffd9"),
87n/a (b"abc\xEA\xFC", "replace", "abc\ufffd\ufffd"),
88n/a (b"abc\xFF\x58", "replace", "abc\ufffdX"),
89n/a )
90n/a
91n/aclass Test_SJIS_2004(multibytecodec_support.TestBase, unittest.TestCase):
92n/a encoding = 'shift_jis_2004'
93n/a tstring = multibytecodec_support.load_teststring('shift_jis')
94n/a codectests = shiftjis_commonenctests + (
95n/a (b"\\\x7e", "strict", "\xa5\u203e"),
96n/a (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\\\u2016\u2212"),
97n/a (b"abc\xEA\xFC", "strict", "abc\u64bf"),
98n/a (b"\x81\x39xy", "replace", "\ufffd9xy"),
99n/a (b"\xFF\x58xy", "replace", "\ufffdXxy"),
100n/a (b"\x80\x80\x82\x84xy", "replace", "\ufffd\ufffd\uff44xy"),
101n/a (b"\x80\x80\x82\x84\x88xy", "replace", "\ufffd\ufffd\uff44\u5864y"),
102n/a (b"\xFC\xFBxy", "replace", '\ufffd\u95b4y'),
103n/a )
104n/a xmlcharnametest = (
105n/a "\xab\u211c\xbb = \u2329\u1234\u232a",
106n/a b"\x85Gℜ\x85Q = ⟨ሴ⟩"
107n/a )
108n/a
109n/aclass Test_SJISX0213(multibytecodec_support.TestBase, unittest.TestCase):
110n/a encoding = 'shift_jisx0213'
111n/a tstring = multibytecodec_support.load_teststring('shift_jisx0213')
112n/a codectests = shiftjis_commonenctests + (
113n/a (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"),
114n/a (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"),
115n/a
116n/a # sjis vs cp932
117n/a (b"\\\x7e", "replace", "\xa5\u203e"),
118n/a (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"),
119n/a )
120n/a xmlcharnametest = (
121n/a "\xab\u211c\xbb = \u2329\u1234\u232a",
122n/a b"\x85Gℜ\x85Q = ⟨ሴ⟩"
123n/a )
124n/a
125n/aif __name__ == "__main__":
126n/a unittest.main()