Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 1 | # |
| 2 | # test_codecencodings_jp.py |
| 3 | # Codec encoding tests for Japanese encodings. |
| 4 | # |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 5 | |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 6 | from test import support |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 7 | from test import multibytecodec_support |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 8 | import unittest |
| 9 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 10 | class Test_CP932(multibytecodec_support.TestBase, unittest.TestCase): |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 11 | encoding = 'cp932' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 12 | tstring = multibytecodec_support.load_teststring('shift_jis') |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 13 | codectests = ( |
| 14 | # invalid bytes |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 15 | (b"abc\x81\x00\x81\x00\x82\x84", "strict", None), |
| 16 | (b"abc\xf8", "strict", None), |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 17 | (b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\x00\uff44"), |
| 18 | (b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\x00\uff44\ufffd"), |
| 19 | (b"abc\x81\x00\x82\x84", "ignore", "abc\x00\uff44"), |
| 20 | (b"ab\xEBxy", "replace", "ab\uFFFDxy"), |
| 21 | (b"ab\xF0\x39xy", "replace", "ab\uFFFD9xy"), |
| 22 | (b"ab\xEA\xF0xy", "replace", 'ab\ufffd\ue038y'), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 23 | # sjis vs cp932 |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 24 | (b"\\\x7e", "replace", "\\\x7e"), |
| 25 | (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 26 | ) |
| 27 | |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 28 | euc_commontests = ( |
| 29 | # invalid bytes |
| 30 | (b"abc\x80\x80\xc1\xc4", "strict", None), |
| 31 | (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u7956"), |
| 32 | (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u7956\ufffd"), |
| 33 | (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), |
| 34 | (b"abc\xc8", "strict", None), |
| 35 | (b"abc\x8f\x83\x83", "replace", "abc\ufffd\ufffd\ufffd"), |
| 36 | (b"\x82\xFCxy", "replace", "\ufffd\ufffdxy"), |
| 37 | (b"\xc1\x64", "strict", None), |
| 38 | (b"\xa1\xc0", "strict", "\uff3c"), |
| 39 | (b"\xa1\xc0\\", "strict", "\uff3c\\"), |
| 40 | (b"\x8eXY", "replace", "\ufffdXY"), |
| 41 | ) |
| 42 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 43 | class Test_EUC_JIS_2004(multibytecodec_support.TestBase, |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 44 | unittest.TestCase): |
| 45 | encoding = 'euc_jis_2004' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 46 | tstring = multibytecodec_support.load_teststring('euc_jisx0213') |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 47 | codectests = euc_commontests |
| 48 | xmlcharnametest = ( |
| 49 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
| 50 | b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" |
| 51 | ) |
| 52 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 53 | class Test_EUC_JISX0213(multibytecodec_support.TestBase, |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 54 | unittest.TestCase): |
| 55 | encoding = 'euc_jisx0213' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 56 | tstring = multibytecodec_support.load_teststring('euc_jisx0213') |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 57 | codectests = euc_commontests |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 58 | xmlcharnametest = ( |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 59 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 60 | b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 61 | ) |
| 62 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 63 | class Test_EUC_JP_COMPAT(multibytecodec_support.TestBase, |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 64 | unittest.TestCase): |
| 65 | encoding = 'euc_jp' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 66 | tstring = multibytecodec_support.load_teststring('euc_jp') |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 67 | codectests = euc_commontests + ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 68 | ("\xa5", "strict", b"\x5c"), |
| 69 | ("\u203e", "strict", b"\x7e"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 70 | ) |
| 71 | |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 72 | shiftjis_commonenctests = ( |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 73 | (b"abc\x80\x80\x82\x84", "strict", None), |
| 74 | (b"abc\xf8", "strict", None), |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 75 | (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 76 | ) |
| 77 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 78 | class Test_SJIS_COMPAT(multibytecodec_support.TestBase, unittest.TestCase): |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 79 | encoding = 'shift_jis' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 80 | tstring = multibytecodec_support.load_teststring('shift_jis') |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 81 | codectests = shiftjis_commonenctests + ( |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 82 | (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"), |
| 83 | (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"), |
| 84 | |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 85 | (b"\\\x7e", "strict", "\\\x7e"), |
| 86 | (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"), |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 87 | (b"abc\x81\x39", "replace", "abc\ufffd9"), |
| 88 | (b"abc\xEA\xFC", "replace", "abc\ufffd\ufffd"), |
| 89 | (b"abc\xFF\x58", "replace", "abc\ufffdX"), |
| 90 | ) |
| 91 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 92 | class Test_SJIS_2004(multibytecodec_support.TestBase, unittest.TestCase): |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 93 | encoding = 'shift_jis_2004' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 94 | tstring = multibytecodec_support.load_teststring('shift_jis') |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 95 | codectests = shiftjis_commonenctests + ( |
| 96 | (b"\\\x7e", "strict", "\xa5\u203e"), |
| 97 | (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\\\u2016\u2212"), |
| 98 | (b"abc\xEA\xFC", "strict", "abc\u64bf"), |
| 99 | (b"\x81\x39xy", "replace", "\ufffd9xy"), |
| 100 | (b"\xFF\x58xy", "replace", "\ufffdXxy"), |
| 101 | (b"\x80\x80\x82\x84xy", "replace", "\ufffd\ufffd\uff44xy"), |
| 102 | (b"\x80\x80\x82\x84\x88xy", "replace", "\ufffd\ufffd\uff44\u5864y"), |
| 103 | (b"\xFC\xFBxy", "replace", '\ufffd\u95b4y'), |
| 104 | ) |
| 105 | xmlcharnametest = ( |
| 106 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
| 107 | b"\x85Gℜ\x85Q = ⟨ሴ⟩" |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 108 | ) |
| 109 | |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 110 | class Test_SJISX0213(multibytecodec_support.TestBase, unittest.TestCase): |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 111 | encoding = 'shift_jisx0213' |
R David Murray | 75d9aca | 2012-04-09 09:37:52 -0400 | [diff] [blame] | 112 | tstring = multibytecodec_support.load_teststring('shift_jisx0213') |
Victor Stinner | 2cded9c | 2011-07-08 01:45:13 +0200 | [diff] [blame] | 113 | codectests = shiftjis_commonenctests + ( |
| 114 | (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"), |
| 115 | (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"), |
| 116 | |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 117 | # sjis vs cp932 |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 118 | (b"\\\x7e", "replace", "\xa5\u203e"), |
| 119 | (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"), |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 120 | ) |
| 121 | xmlcharnametest = ( |
Guido van Rossum | ef87d6e | 2007-05-02 19:09:54 +0000 | [diff] [blame] | 122 | "\xab\u211c\xbb = \u2329\u1234\u232a", |
Guido van Rossum | 024da5c | 2007-05-17 23:59:11 +0000 | [diff] [blame] | 123 | b"\x85Gℜ\x85Q = ⟨ሴ⟩" |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 124 | ) |
| 125 | |
Hye-Shik Chang | 3e2a306 | 2004-01-17 14:29:29 +0000 | [diff] [blame] | 126 | if __name__ == "__main__": |
Zachary Ware | 38c707e | 2015-04-13 15:00:43 -0500 | [diff] [blame] | 127 | unittest.main() |