2004-01-17 22:29:29 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# test_codecencodings_kr.py
|
|
|
|
# Codec encoding tests for ROK encodings.
|
|
|
|
#
|
|
|
|
|
2008-05-21 05:35:26 +08:00
|
|
|
from test import support
|
2004-01-17 22:29:29 +08:00
|
|
|
from test import test_multibytecodec_support
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
class Test_CP949(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'cp949'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('cp949')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_EUCKR(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'euc_kr'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('euc_kr')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"),
|
2007-08-21 03:06:03 +08:00
|
|
|
|
|
|
|
# composed make-up sequence errors
|
|
|
|
(b"\xa4\xd4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "strict", "\uc4d4"),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4x", "strict", "\uc4d4x"),
|
|
|
|
(b"a\xa4\xd4\xa4\xb6\xa4", "replace", "a\ufffd"),
|
|
|
|
(b"\xa4\xd4\xa3\xb6\xa4\xd0\xa4\xd4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa3\xd0\xa4\xd4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0\xa3\xd4", "strict", None),
|
|
|
|
(b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", "\ufffd"),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", "\ufffd"),
|
|
|
|
(b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", "\ufffd"),
|
|
|
|
(b"\xc1\xc4", "strict", "\uc894"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
class Test_JOHAB(test_multibytecodec_support.TestBase, unittest.TestCase):
|
|
|
|
encoding = 'johab'
|
|
|
|
tstring = test_multibytecodec_support.load_teststring('johab')
|
|
|
|
codectests = (
|
|
|
|
# invalid bytes
|
2007-05-18 07:59:11 +08:00
|
|
|
(b"abc\x80\x80\xc1\xc4", "strict", None),
|
|
|
|
(b"abc\xc8", "strict", None),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ucd27"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ucd27\ufffd"),
|
|
|
|
(b"abc\x80\x80\xc1\xc4", "ignore", "abc\ucd27"),
|
2004-01-17 22:29:29 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_main():
|
2008-05-21 05:35:26 +08:00
|
|
|
support.run_unittest(__name__)
|
2004-01-17 22:29:29 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|