Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 2 | # |
| 3 | # test_codecencodings_cn.py |
| 4 | # Codec encoding tests for PRC encodings. |
| 5 | # |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 6 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 7 | from test import support |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 8 | from test import test_multibytecodec_support |
| 9 | import unittest |
| 10 | |
| 11 | class Test_GB2312(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 12 | encoding = 'gb2312' |
| 13 | tstring = test_multibytecodec_support.load_teststring('gb2312') |
| 14 | codectests = ( |
| 15 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 16 | (b"abc\x81\x81\xc1\xc4", "strict", None), |
| 17 | (b"abc\xc8", "strict", None), |
| 18 | (b"abc\x81\x81\xc1\xc4", "replace", "abc\ufffd\u804a"), |
| 19 | (b"abc\x81\x81\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), |
| 20 | (b"abc\x81\x81\xc1\xc4", "ignore", "abc\u804a"), |
| 21 | (b"\xc1\x64", "strict", None), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 25 | encoding = 'gbk' |
| 26 | tstring = test_multibytecodec_support.load_teststring('gbk') |
| 27 | codectests = ( |
| 28 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 29 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 30 | (b"abc\xc8", "strict", None), |
| 31 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u804a"), |
| 32 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), |
| 33 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"), |
| 34 | (b"\x83\x34\x83\x31", "strict", None), |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 35 | ("\u30fb", "strict", None), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 36 | ) |
| 37 | |
| 38 | class Test_GB18030(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 39 | encoding = 'gb18030' |
| 40 | tstring = test_multibytecodec_support.load_teststring('gb18030') |
| 41 | codectests = ( |
| 42 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 43 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 44 | (b"abc\xc8", "strict", None), |
| 45 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u804a"), |
| 46 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), |
| 47 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"), |
| 48 | (b"abc\x84\x39\x84\x39\xc1\xc4", "replace", "abc\ufffd\u804a"), |
| 49 | ("\u30fb", "strict", b"\x819\xa79"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 50 | ) |
| 51 | has_iso10646 = True |
| 52 | |
| 53 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 54 | support.run_unittest(__name__) |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 55 | |
| 56 | if __name__ == "__main__": |
| 57 | test_main() |