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