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