2004-01-17 22:29:29 +08:00
|
|
|
#
|
|
|
|
# test_codecencodings_jp.py
|
|
|
|
# Codec encoding tests for Japanese encodings.
|
|
|
|
#
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
from test import multibytecodec_support
|
2004-01-17 22:29:29 +08:00
|
|
|
import unittest
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_CP932(multibytecodec_support.TestBase, unittest.TestCase):
|
2004-01-17 22:29:29 +08:00
|
|
|
encoding = 'cp932'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('shift_jis')
|
2004-01-17 22:29:29 +08:00
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"abc\x81\x00\x81\x00\x82\x84", "strict", None),
|
|
|
|
(b"abc\xf8", "strict", None),
|
2011-07-08 07:45:13 +08:00
|
|
|
(b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\x00\uff44"),
|
|
|
|
(b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\x00\uff44\ufffd"),
|
|
|
|
(b"abc\x81\x00\x82\x84", "ignore", "abc\x00\uff44"),
|
|
|
|
(b"ab\xEBxy", "replace", "ab\uFFFDxy"),
|
|
|
|
(b"ab\xF0\x39xy", "replace", "ab\uFFFD9xy"),
|
|
|
|
(b"ab\xEA\xF0xy", "replace", 'ab\ufffd\ue038y'),
|
2004-01-17 22:29:29 +08:00
|
|
|
# sjis vs cp932
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"\\\x7e", "replace", "\\\x7e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
2011-07-08 07:45:13 +08:00
|
|
|
euc_commontests = (
|
|
|
|
# invalid bytes
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u7956"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u7956\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x8f\x83\x83", "replace", "abc\ufffd\ufffd\ufffd"),
|
|
|
|
(b"\x82\xFCxy", "replace", "\ufffd\ufffdxy"),
|
|
|
|
(b"\xc1\x64", "strict", None),
|
|
|
|
(b"\xa1\xc0", "strict", "\uff3c"),
|
|
|
|
(b"\xa1\xc0\\", "strict", "\uff3c\\"),
|
|
|
|
(b"\x8eXY", "replace", "\ufffdXY"),
|
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_EUC_JIS_2004(multibytecodec_support.TestBase,
|
2011-07-08 07:45:13 +08:00
|
|
|
unittest.TestCase):
|
|
|
|
encoding = 'euc_jis_2004'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('euc_jisx0213')
|
2011-07-08 07:45:13 +08:00
|
|
|
codectests = euc_commontests
|
|
|
|
xmlcharnametest = (
|
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
|
|
|
b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
|
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_EUC_JISX0213(multibytecodec_support.TestBase,
|
2004-01-17 22:29:29 +08:00
|
|
|
unittest.TestCase):
|
|
|
|
encoding = 'euc_jisx0213'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('euc_jisx0213')
|
2011-07-08 07:45:13 +08:00
|
|
|
codectests = euc_commontests
|
2004-01-17 22:29:29 +08:00
|
|
|
xmlcharnametest = (
|
2007-05-03 03:09:54 +08:00
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
2007-05-18 07:59:11 +08:00
|
|
|
b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_EUC_JP_COMPAT(multibytecodec_support.TestBase,
|
2004-01-17 22:29:29 +08:00
|
|
|
unittest.TestCase):
|
|
|
|
encoding = 'euc_jp'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('euc_jp')
|
2011-07-08 07:45:13 +08:00
|
|
|
codectests = euc_commontests + (
|
2007-05-18 07:59:11 +08:00
|
|
|
("\xa5", "strict", b"\x5c"),
|
|
|
|
("\u203e", "strict", b"\x7e"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
shiftjis_commonenctests = (
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"abc\x80\x80\x82\x84", "strict", None),
|
|
|
|
(b"abc\xf8", "strict", None),
|
|
|
|
(b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_SJIS_COMPAT(multibytecodec_support.TestBase, unittest.TestCase):
|
2004-01-17 22:29:29 +08:00
|
|
|
encoding = 'shift_jis'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('shift_jis')
|
2004-01-17 22:29:29 +08:00
|
|
|
codectests = shiftjis_commonenctests + (
|
2011-07-08 07:45:13 +08:00
|
|
|
(b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"),
|
|
|
|
(b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"),
|
|
|
|
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"\\\x7e", "strict", "\\\x7e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"),
|
2011-07-08 07:45:13 +08:00
|
|
|
(b"abc\x81\x39", "replace", "abc\ufffd9"),
|
|
|
|
(b"abc\xEA\xFC", "replace", "abc\ufffd\ufffd"),
|
|
|
|
(b"abc\xFF\x58", "replace", "abc\ufffdX"),
|
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_SJIS_2004(multibytecodec_support.TestBase, unittest.TestCase):
|
2011-07-08 07:45:13 +08:00
|
|
|
encoding = 'shift_jis_2004'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('shift_jis')
|
2011-07-08 07:45:13 +08:00
|
|
|
codectests = shiftjis_commonenctests + (
|
|
|
|
(b"\\\x7e", "strict", "\xa5\u203e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "strict", "\\\u2016\u2212"),
|
|
|
|
(b"abc\xEA\xFC", "strict", "abc\u64bf"),
|
|
|
|
(b"\x81\x39xy", "replace", "\ufffd9xy"),
|
|
|
|
(b"\xFF\x58xy", "replace", "\ufffdXxy"),
|
|
|
|
(b"\x80\x80\x82\x84xy", "replace", "\ufffd\ufffd\uff44xy"),
|
|
|
|
(b"\x80\x80\x82\x84\x88xy", "replace", "\ufffd\ufffd\uff44\u5864y"),
|
|
|
|
(b"\xFC\xFBxy", "replace", '\ufffd\u95b4y'),
|
|
|
|
)
|
|
|
|
xmlcharnametest = (
|
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
|
|
|
b"\x85Gℜ\x85Q = ⟨ሴ⟩"
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
2012-04-09 21:37:52 +08:00
|
|
|
class Test_SJISX0213(multibytecodec_support.TestBase, unittest.TestCase):
|
2004-01-17 22:29:29 +08:00
|
|
|
encoding = 'shift_jisx0213'
|
2012-04-09 21:37:52 +08:00
|
|
|
tstring = multibytecodec_support.load_teststring('shift_jisx0213')
|
2011-07-08 07:45:13 +08:00
|
|
|
codectests = shiftjis_commonenctests + (
|
|
|
|
(b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"),
|
|
|
|
(b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"),
|
|
|
|
|
2004-01-17 22:29:29 +08:00
|
|
|
# sjis vs cp932
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"\\\x7e", "replace", "\xa5\u203e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
xmlcharnametest = (
|
2007-05-03 03:09:54 +08:00
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
2007-05-18 07:59:11 +08:00
|
|
|
b"\x85Gℜ\x85Q = ⟨ሴ⟩"
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-04-14 04:00:43 +08:00
|
|
|
unittest.main()
|