1#!/usr/bin/env python
2#
3# test_codecencodings_kr.py
4#   Codec encoding tests for ROK encodings.
5#
6
7from test import test_support
8from test import test_multibytecodec_support
9import unittest
10
11class Test_CP949(test_multibytecodec_support.TestBase, unittest.TestCase):
12    encoding = 'cp949'
13    tstring = test_multibytecodec_support.load_teststring('cp949')
14    codectests = (
15        # invalid bytes
16        ("abc\x80\x80\xc1\xc4", "strict",  None),
17        ("abc\xc8", "strict",  None),
18        ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\uc894"),
19        ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\uc894\ufffd"),
20        ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\uc894"),
21    )
22
23class Test_EUCKR(test_multibytecodec_support.TestBase, unittest.TestCase):
24    encoding = 'euc_kr'
25    tstring = test_multibytecodec_support.load_teststring('euc_kr')
26    codectests = (
27        # invalid bytes
28        ("abc\x80\x80\xc1\xc4", "strict",  None),
29        ("abc\xc8", "strict",  None),
30        ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\uc894"),
31        ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\uc894\ufffd"),
32        ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\uc894"),
33
34        # composed make-up sequence errors
35        ("\xa4\xd4", "strict", None),
36        ("\xa4\xd4\xa4", "strict", None),
37        ("\xa4\xd4\xa4\xb6", "strict", None),
38        ("\xa4\xd4\xa4\xb6\xa4", "strict", None),
39        ("\xa4\xd4\xa4\xb6\xa4\xd0", "strict", None),
40        ("\xa4\xd4\xa4\xb6\xa4\xd0\xa4", "strict", None),
41        ("\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "strict", u"\uc4d4"),
42        ("\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4x", "strict", u"\uc4d4x"),
43        ("a\xa4\xd4\xa4\xb6\xa4", "replace", u"a\ufffd"),
44        ("\xa4\xd4\xa3\xb6\xa4\xd0\xa4\xd4", "strict", None),
45        ("\xa4\xd4\xa4\xb6\xa3\xd0\xa4\xd4", "strict", None),
46        ("\xa4\xd4\xa4\xb6\xa4\xd0\xa3\xd4", "strict", None),
47        ("\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", u"\ufffd"),
48        ("\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", u"\ufffd"),
49        ("\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", u"\ufffd"),
50        ("\xc1\xc4", "strict", u"\uc894"),
51    )
52
53class Test_JOHAB(test_multibytecodec_support.TestBase, unittest.TestCase):
54    encoding = 'johab'
55    tstring = test_multibytecodec_support.load_teststring('johab')
56    codectests = (
57        # invalid bytes
58        ("abc\x80\x80\xc1\xc4", "strict",  None),
59        ("abc\xc8", "strict",  None),
60        ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\ucd27"),
61        ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\ucd27\ufffd"),
62        ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\ucd27"),
63    )
64
65def test_main():
66    test_support.run_unittest(__name__)
67
68if __name__ == "__main__":
69    test_main()
70