2004-01-17 10:29:29 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# test_codecencodings_jp.py
|
|
|
|
# Codec encoding tests for Japanese encodings.
|
|
|
|
#
|
|
|
|
|
2008-05-20 18:35:26 -03:00
|
|
|
from test import support
|
2004-01-17 10:29:29 -04:00
|
|
|
from test import test_multibytecodec_support
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
class Test_CP932(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'cp932'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('shift_jis')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"abc\x81\x00\x81\x00\x82\x84", "strict", None),
|
|
|
|
(b"abc\xf8", "strict", None),
|
|
|
|
(b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\uff44"),
|
|
|
|
(b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"),
|
|
|
|
(b"abc\x81\x00\x82\x84", "ignore", "abc\uff44"),
|
2004-01-17 10:29:29 -04:00
|
|
|
# sjis vs cp932
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"\\\x7e", "replace", "\\\x7e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_EUC_JISX0213(test_multibytecodec_support.TestBase,
|
|
|
|
unittest.TestCase):
|
|
|
|
encoding = 'euc_jisx0213'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('euc_jisx0213')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"),
|
|
|
|
(b"abc\x8f\x83\x83", "replace", "abc\ufffd"),
|
|
|
|
(b"\xc1\x64", "strict", None),
|
|
|
|
(b"\xa1\xc0", "strict", "\uff3c"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
xmlcharnametest = (
|
2007-05-02 16:09:54 -03:00
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
2007-05-17 20:59:11 -03:00
|
|
|
b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
eucjp_commontests = (
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"),
|
|
|
|
(b"abc\x8f\x83\x83", "replace", "abc\ufffd"),
|
|
|
|
(b"\xc1\x64", "strict", None),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase,
|
|
|
|
unittest.TestCase):
|
|
|
|
encoding = 'euc_jp'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('euc_jp')
|
|
|
|
codectests = eucjp_commontests + (
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"\xa1\xc0\\", "strict", "\uff3c\\"),
|
|
|
|
("\xa5", "strict", b"\x5c"),
|
|
|
|
("\u203e", "strict", b"\x7e"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
shiftjis_commonenctests = (
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"abc\x80\x80\x82\x84", "strict", None),
|
|
|
|
(b"abc\xf8", "strict", None),
|
|
|
|
(b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"),
|
|
|
|
(b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"),
|
|
|
|
(b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'shift_jis'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('shift_jis')
|
|
|
|
codectests = shiftjis_commonenctests + (
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"\\\x7e", "strict", "\\\x7e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'shift_jisx0213'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('shift_jisx0213')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"abc\x80\x80\x82\x84", "strict", None),
|
|
|
|
(b"abc\xf8", "strict", None),
|
|
|
|
(b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"),
|
|
|
|
(b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"),
|
|
|
|
(b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"),
|
2004-01-17 10:29:29 -04:00
|
|
|
# sjis vs cp932
|
2007-05-17 20:59:11 -03:00
|
|
|
(b"\\\x7e", "replace", "\xa5\u203e"),
|
|
|
|
(b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"),
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
xmlcharnametest = (
|
2007-05-02 16:09:54 -03:00
|
|
|
"\xab\u211c\xbb = \u2329\u1234\u232a",
|
2007-05-17 20:59:11 -03:00
|
|
|
b"\x85Gℜ\x85Q = ⟨ሴ⟩"
|
2004-01-17 10:29:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_main():
|
2008-05-20 18:35:26 -03:00
|
|
|
support.run_unittest(__name__)
|
2004-01-17 10:29:29 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|