Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # test_codecencodings_jp.py |
| 4 | # Codec encoding tests for Japanese 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_CP932(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 12 | encoding = 'cp932' |
| 13 | tstring = test_multibytecodec_support.load_teststring('shift_jis') |
| 14 | codectests = ( |
| 15 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 16 | (b"abc\x81\x00\x81\x00\x82\x84", "strict", None), |
| 17 | (b"abc\xf8", "strict", None), |
| 18 | (b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\uff44"), |
| 19 | (b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), |
| 20 | (b"abc\x81\x00\x82\x84", "ignore", "abc\uff44"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 21 | # sjis vs cp932 |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 22 | (b"\\\x7e", "replace", "\\\x7e"), |
| 23 | (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | class Test_EUC_JISX0213(test_multibytecodec_support.TestBase, |
| 27 | unittest.TestCase): |
| 28 | encoding = 'euc_jisx0213' |
| 29 | tstring = test_multibytecodec_support.load_teststring('euc_jisx0213') |
| 30 | codectests = ( |
| 31 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 32 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 33 | (b"abc\xc8", "strict", None), |
| 34 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"), |
| 35 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"), |
| 36 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), |
| 37 | (b"abc\x8f\x83\x83", "replace", "abc\ufffd"), |
| 38 | (b"\xc1\x64", "strict", None), |
| 39 | (b"\xa1\xc0", "strict", "\uff3c"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 40 | ) |
| 41 | xmlcharnametest = ( |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 42 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 43 | b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 44 | ) |
| 45 | |
| 46 | eucjp_commontests = ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 47 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 48 | (b"abc\xc8", "strict", None), |
| 49 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"), |
| 50 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"), |
| 51 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), |
| 52 | (b"abc\x8f\x83\x83", "replace", "abc\ufffd"), |
| 53 | (b"\xc1\x64", "strict", None), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 54 | ) |
| 55 | |
| 56 | class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase, |
| 57 | unittest.TestCase): |
| 58 | encoding = 'euc_jp' |
| 59 | tstring = test_multibytecodec_support.load_teststring('euc_jp') |
| 60 | codectests = eucjp_commontests + ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 61 | (b"\xa1\xc0\\", "strict", "\uff3c\\"), |
| 62 | ("\xa5", "strict", b"\x5c"), |
| 63 | ("\u203e", "strict", b"\x7e"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 64 | ) |
| 65 | |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 66 | shiftjis_commonenctests = ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 67 | (b"abc\x80\x80\x82\x84", "strict", None), |
| 68 | (b"abc\xf8", "strict", None), |
| 69 | (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"), |
| 70 | (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), |
| 71 | (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 72 | ) |
| 73 | |
| 74 | class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 75 | encoding = 'shift_jis' |
| 76 | tstring = test_multibytecodec_support.load_teststring('shift_jis') |
| 77 | codectests = shiftjis_commonenctests + ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 78 | (b"\\\x7e", "strict", "\\\x7e"), |
| 79 | (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 80 | ) |
| 81 | |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 82 | class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase): |
| 83 | encoding = 'shift_jisx0213' |
| 84 | tstring = test_multibytecodec_support.load_teststring('shift_jisx0213') |
| 85 | codectests = ( |
| 86 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 87 | (b"abc\x80\x80\x82\x84", "strict", None), |
| 88 | (b"abc\xf8", "strict", None), |
| 89 | (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"), |
| 90 | (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), |
| 91 | (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 92 | # sjis vs cp932 |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 93 | (b"\\\x7e", "replace", "\xa5\u203e"), |
| 94 | (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 95 | ) |
| 96 | xmlcharnametest = ( |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 97 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 98 | b"\x85Gℜ\x85Q = ⟨ሴ⟩" |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 99 | ) |
| 100 | |
| 101 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 102 | support.run_unittest(__name__) |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 103 | |
| 104 | if __name__ == "__main__": |
| 105 | test_main() |