1# 2# test_codecencodings_kr.py 3# Codec encoding tests for ROK encodings. 4# 5 6from test import multibytecodec_support 7import unittest 8 9class Test_CP949(multibytecodec_support.TestBase, unittest.TestCase): 10 encoding = 'cp949' 11 tstring = multibytecodec_support.load_teststring('cp949') 12 codectests = ( 13 # invalid bytes 14 (b"abc\x80\x80\xc1\xc4", "strict", None), 15 (b"abc\xc8", "strict", None), 16 (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\uc894"), 17 (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 21class Test_EUCKR(multibytecodec_support.TestBase, unittest.TestCase): 22 encoding = 'euc_kr' 23 tstring = multibytecodec_support.load_teststring('euc_kr') 24 codectests = ( 25 # invalid bytes 26 (b"abc\x80\x80\xc1\xc4", "strict", None), 27 (b"abc\xc8", "strict", None), 28 (b"abc\x80\x80\xc1\xc4", "replace", 'abc\ufffd\ufffd\uc894'), 29 (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 # composed make-up sequence errors 33 (b"\xa4\xd4", "strict", None), 34 (b"\xa4\xd4\xa4", "strict", None), 35 (b"\xa4\xd4\xa4\xb6", "strict", None), 36 (b"\xa4\xd4\xa4\xb6\xa4", "strict", None), 37 (b"\xa4\xd4\xa4\xb6\xa4\xd0", "strict", None), 38 (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4", "strict", None), 39 (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "strict", "\uc4d4"), 40 (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4x", "strict", "\uc4d4x"), 41 (b"a\xa4\xd4\xa4\xb6\xa4", "replace", 'a\ufffd'), 42 (b"\xa4\xd4\xa3\xb6\xa4\xd0\xa4\xd4", "strict", None), 43 (b"\xa4\xd4\xa4\xb6\xa3\xd0\xa4\xd4", "strict", None), 44 (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa3\xd4", "strict", None), 45 (b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", '\ufffd\u6e21\ufffd\u3160\ufffd'), 46 (b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", '\ufffd\u6e21\ub544\ufffd\ufffd'), 47 (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", '\ufffd\u6e21\ub544\u572d\ufffd'), 48 (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 52class Test_JOHAB(multibytecodec_support.TestBase, unittest.TestCase): 53 encoding = 'johab' 54 tstring = multibytecodec_support.load_teststring('johab') 55 codectests = ( 56 # invalid bytes 57 (b"abc\x80\x80\xc1\xc4", "strict", None), 58 (b"abc\xc8", "strict", None), 59 (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\ucd27"), 60 (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\ucd27\ufffd"), 61 (b"abc\x80\x80\xc1\xc4", "ignore", "abc\ucd27"), 62 (b"\xD8abc", "replace", "\uFFFDabc"), 63 (b"\xD8\xFFabc", "replace", "\uFFFD\uFFFDabc"), 64 (b"\x84bxy", "replace", "\uFFFDbxy"), 65 (b"\x8CBxy", "replace", "\uFFFDBxy"), 66 ) 67 68if __name__ == "__main__": 69 unittest.main() 70