test_codecencodings_kr.py 2.96 KB
Newer Older
1 2 3 4 5
#
# test_codecencodings_kr.py
#   Codec encoding tests for ROK encodings.
#

6
from test import multibytecodec_support
7 8
import unittest

9
class Test_CP949(multibytecodec_support.TestBase, unittest.TestCase):
10
    encoding = 'cp949'
11
    tstring = multibytecodec_support.load_teststring('cp949')
12 13
    codectests = (
        # invalid bytes
14 15
        (b"abc\x80\x80\xc1\xc4", "strict",  None),
        (b"abc\xc8", "strict",  None),
16 17
        (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\uc894"),
        (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\uc894\ufffd"),
18
        (b"abc\x80\x80\xc1\xc4", "ignore",  "abc\uc894"),
19 20
    )

21
class Test_EUCKR(multibytecodec_support.TestBase, unittest.TestCase):
22
    encoding = 'euc_kr'
23
    tstring = multibytecodec_support.load_teststring('euc_kr')
24 25
    codectests = (
        # invalid bytes
26 27
        (b"abc\x80\x80\xc1\xc4", "strict",  None),
        (b"abc\xc8", "strict",  None),
28 29
        (b"abc\x80\x80\xc1\xc4", "replace", 'abc\ufffd\ufffd\uc894'),
        (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\uc894\ufffd"),
30
        (b"abc\x80\x80\xc1\xc4", "ignore",  "abc\uc894"),
31 32 33 34 35 36 37 38 39 40

        # 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"),
41
        (b"a\xa4\xd4\xa4\xb6\xa4", "replace", 'a\ufffd'),
42 43 44
        (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),
45 46 47 48
        (b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", '\ufffd\u6e21\ufffd\u3160\ufffd'),
        (b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", '\ufffd\u6e21\ub544\ufffd\ufffd'),
        (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", '\ufffd\u6e21\ub544\u572d\ufffd'),
        (b"\xa4\xd4\xff\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "replace", '\ufffd\ufffd\ufffd\uc4d4'),
49
        (b"\xc1\xc4", "strict", "\uc894"),
50 51
    )

52
class Test_JOHAB(multibytecodec_support.TestBase, unittest.TestCase):
53
    encoding = 'johab'
54
    tstring = multibytecodec_support.load_teststring('johab')
55 56
    codectests = (
        # invalid bytes
57 58
        (b"abc\x80\x80\xc1\xc4", "strict",  None),
        (b"abc\xc8", "strict",  None),
59 60
        (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\ucd27"),
        (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\ucd27\ufffd"),
61
        (b"abc\x80\x80\xc1\xc4", "ignore",  "abc\ucd27"),
62 63 64 65
        (b"\xD8abc", "replace",  "\uFFFDabc"),
        (b"\xD8\xFFabc", "replace",  "\uFFFD\uFFFDabc"),
        (b"\x84bxy", "replace",  "\uFFFDbxy"),
        (b"\x8CBxy", "replace",  "\uFFFDBxy"),
66 67 68
    )

if __name__ == "__main__":
69
    unittest.main()