]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | #!/usr/bin/env python\r |
2 | #\r | |
3 | # test_codecencodings_cn.py\r | |
4 | # Codec encoding tests for PRC 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_GB2312(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
12 | encoding = 'gb2312'\r | |
13 | tstring = test_multibytecodec_support.load_teststring('gb2312')\r | |
14 | codectests = (\r | |
15 | # invalid bytes\r | |
16 | ("abc\x81\x81\xc1\xc4", "strict", None),\r | |
17 | ("abc\xc8", "strict", None),\r | |
18 | ("abc\x81\x81\xc1\xc4", "replace", u"abc\ufffd\u804a"),\r | |
19 | ("abc\x81\x81\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),\r | |
20 | ("abc\x81\x81\xc1\xc4", "ignore", u"abc\u804a"),\r | |
21 | ("\xc1\x64", "strict", None),\r | |
22 | )\r | |
23 | \r | |
24 | class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
25 | encoding = 'gbk'\r | |
26 | tstring = test_multibytecodec_support.load_teststring('gbk')\r | |
27 | codectests = (\r | |
28 | # invalid bytes\r | |
29 | ("abc\x80\x80\xc1\xc4", "strict", None),\r | |
30 | ("abc\xc8", "strict", None),\r | |
31 | ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),\r | |
32 | ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),\r | |
33 | ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"),\r | |
34 | ("\x83\x34\x83\x31", "strict", None),\r | |
35 | (u"\u30fb", "strict", None),\r | |
36 | )\r | |
37 | \r | |
38 | class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
39 | encoding = 'gb18030'\r | |
40 | tstring = test_multibytecodec_support.load_teststring('gb18030')\r | |
41 | codectests = (\r | |
42 | # invalid bytes\r | |
43 | ("abc\x80\x80\xc1\xc4", "strict", None),\r | |
44 | ("abc\xc8", "strict", None),\r | |
45 | ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"),\r | |
46 | ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"),\r | |
47 | ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"),\r | |
48 | ("abc\x84\x39\x84\x39\xc1\xc4", "replace", u"abc\ufffd\u804a"),\r | |
49 | (u"\u30fb", "strict", "\x819\xa79"),\r | |
50 | )\r | |
51 | has_iso10646 = True\r | |
52 | \r | |
53 | class Test_HZ(test_multibytecodec_support.TestBase, unittest.TestCase):\r | |
54 | encoding = 'hz'\r | |
55 | tstring = test_multibytecodec_support.load_teststring('hz')\r | |
56 | codectests = (\r | |
57 | # test '~\n' (3 lines)\r | |
58 | (b'This sentence is in ASCII.\n'\r | |
59 | b'The next sentence is in GB.~{<:Ky2;S{#,~}~\n'\r | |
60 | b'~{NpJ)l6HK!#~}Bye.\n',\r | |
61 | 'strict',\r | |
62 | u'This sentence is in ASCII.\n'\r | |
63 | u'The next sentence is in GB.'\r | |
64 | u'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'\r | |
65 | u'Bye.\n'),\r | |
66 | # test '~\n' (4 lines)\r | |
67 | (b'This sentence is in ASCII.\n'\r | |
68 | b'The next sentence is in GB.~\n'\r | |
69 | b'~{<:Ky2;S{#,NpJ)l6HK!#~}~\n'\r | |
70 | b'Bye.\n',\r | |
71 | 'strict',\r | |
72 | u'This sentence is in ASCII.\n'\r | |
73 | u'The next sentence is in GB.'\r | |
74 | u'\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002'\r | |
75 | u'Bye.\n'),\r | |
76 | # invalid bytes\r | |
77 | (b'ab~cd', 'replace', u'ab\uFFFDd'),\r | |
78 | (b'ab\xffcd', 'replace', u'ab\uFFFDcd'),\r | |
79 | (b'ab~{\x81\x81\x41\x44~}cd', 'replace', u'ab\uFFFD\uFFFD\u804Acd'),\r | |
80 | )\r | |
81 | \r | |
82 | def test_main():\r | |
83 | test_support.run_unittest(__name__)\r | |
84 | \r | |
85 | if __name__ == "__main__":\r | |
86 | test_main()\r |