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

Python code coverage for Lib/test/test_codecencodings_cn.py

#countcontent
1n/a#
2n/a# test_codecencodings_cn.py
3n/a# Codec encoding tests for PRC encodings.
4n/a#
5n/a
6n/afrom test import multibytecodec_support
7n/aimport unittest
8n/a
9n/aclass Test_GB2312(multibytecodec_support.TestBase, unittest.TestCase):
10n/a encoding = 'gb2312'
11n/a tstring = multibytecodec_support.load_teststring('gb2312')
12n/a codectests = (
13n/a # invalid bytes
14n/a (b"abc\x81\x81\xc1\xc4", "strict", None),
15n/a (b"abc\xc8", "strict", None),
16n/a (b"abc\x81\x81\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"),
17n/a (b"abc\x81\x81\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"),
18n/a (b"abc\x81\x81\xc1\xc4", "ignore", "abc\u804a"),
19n/a (b"\xc1\x64", "strict", None),
20n/a )
21n/a
22n/aclass Test_GBK(multibytecodec_support.TestBase, unittest.TestCase):
23n/a encoding = 'gbk'
24n/a tstring = multibytecodec_support.load_teststring('gbk')
25n/a codectests = (
26n/a # invalid bytes
27n/a (b"abc\x80\x80\xc1\xc4", "strict", None),
28n/a (b"abc\xc8", "strict", None),
29n/a (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"),
30n/a (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"),
31n/a (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"),
32n/a (b"\x83\x34\x83\x31", "strict", None),
33n/a ("\u30fb", "strict", None),
34n/a )
35n/a
36n/aclass Test_GB18030(multibytecodec_support.TestBase, unittest.TestCase):
37n/a encoding = 'gb18030'
38n/a tstring = multibytecodec_support.load_teststring('gb18030')
39n/a codectests = (
40n/a # invalid bytes
41n/a (b"abc\x80\x80\xc1\xc4", "strict", None),
42n/a (b"abc\xc8", "strict", None),
43n/a (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"),
44n/a (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"),
45n/a (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"),
46n/a (b"abc\x84\x39\x84\x39\xc1\xc4", "replace", "abc\ufffd9\ufffd9\u804a"),
47n/a ("\u30fb", "strict", b"\x819\xa79"),
48n/a (b"abc\x84\x32\x80\x80def", "replace", 'abc\ufffd2\ufffd\ufffddef'),
49n/a (b"abc\x81\x30\x81\x30def", "strict", 'abc\x80def'),
50n/a (b"abc\x86\x30\x81\x30def", "replace", 'abc\ufffd0\ufffd0def'),
51n/a )
52n/a has_iso10646 = True
53n/a
54n/aclass Test_HZ(multibytecodec_support.TestBase, unittest.TestCase):
55n/a encoding = 'hz'
56n/a tstring = multibytecodec_support.load_teststring('hz')
57n/a codectests = (
58n/a # test '~\n' (3 lines)
59n/a (b'This sentence is in ASCII.\n'
60n/a b'The next sentence is in GB.~{<:Ky2;S{#,~}~\n'
61n/a b'~{NpJ)l6HK!#~}Bye.\n',
62n/a 'strict',
63n/a 'This sentence is in ASCII.\n'
64n/a 'The next sentence is in GB.'
65n/a '\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'
66n/a 'Bye.\n'),
67n/a # test '~\n' (4 lines)
68n/a (b'This sentence is in ASCII.\n'
69n/a b'The next sentence is in GB.~\n'
70n/a b'~{<:Ky2;S{#,NpJ)l6HK!#~}~\n'
71n/a b'Bye.\n',
72n/a 'strict',
73n/a 'This sentence is in ASCII.\n'
74n/a 'The next sentence is in GB.'
75n/a '\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'
76n/a 'Bye.\n'),
77n/a # invalid bytes
78n/a (b'ab~cd', 'replace', 'ab\uFFFDcd'),
79n/a (b'ab\xffcd', 'replace', 'ab\uFFFDcd'),
80n/a (b'ab~{\x81\x81\x41\x44~}cd', 'replace', 'ab\uFFFD\uFFFD\u804Acd'),
81n/a (b'ab~{\x41\x44~}cd', 'replace', 'ab\u804Acd'),
82n/a (b"ab~{\x79\x79\x41\x44~}cd", "replace", "ab\ufffd\ufffd\u804acd"),
83n/a )
84n/a
85n/aif __name__ == "__main__":
86n/a unittest.main()