Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_codecencodings_kr.Test_EUCKR Class Reference
Inheritance diagram for test.test_codecencodings_kr.Test_EUCKR:
Inheritance graph
[legend]
Collaboration diagram for test.test_codecencodings_kr.Test_EUCKR:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_chunkcoding
def test_errorhandle
def test_xmlcharrefreplace
def test_customreplace_encode
def test_callback_wrong_objects
def test_callback_long_index
def test_callback_None_index
def test_callback_backward_index
def test_callback_forward_index
def test_callback_index_outofbound
def test_incrementalencoder
def test_incrementaldecoder
def test_incrementalencoder_error_callback
def test_streamreader
def test_streamwriter

Public Attributes

 encode
 decode
 reader
 writer
 incrementalencoder
 incrementaldecoder

Static Public Attributes

string encoding = 'euc_kr'
tuple tstring = test_multibytecodec_support.load_teststring('euc_kr')
tuple codectests
 codec = None
int roundtriptest = 1
int has_iso10646 = 0
 xmlcharnametest = None
string unmappedunicode = '\udeee'

Detailed Description

Definition at line 23 of file test_codecencodings_kr.py.


Member Function Documentation

Definition at line 27 of file test_multibytecodec_support.py.

00027 
00028     def setUp(self):
00029         if self.codec is None:
00030             self.codec = codecs.lookup(self.encoding)
00031         self.encode = self.codec.encode
00032         self.decode = self.codec.decode
00033         self.reader = self.codec.streamreader
00034         self.writer = self.codec.streamwriter
00035         self.incrementalencoder = self.codec.incrementalencoder
00036         self.incrementaldecoder = self.codec.incrementaldecoder

Here is the caller graph for this function:

Definition at line 140 of file test_multibytecodec_support.py.

00140 
00141     def test_callback_backward_index(self):
00142         def myreplace(exc):
00143             if myreplace.limit > 0:
00144                 myreplace.limit -= 1
00145                 return ('REPLACED', 0)
00146             else:
00147                 return ('TERMINAL', exc.end)
00148         myreplace.limit = 3
00149         codecs.register_error("test.cjktest", myreplace)
00150         self.assertEqual(self.encode('abcd' + self.unmappedunicode + 'efgh',
00151                                      'test.cjktest'),
00152                 (b'abcdREPLACEDabcdREPLACEDabcdREPLACEDabcdTERMINALefgh', 9))

Here is the call graph for this function:

Definition at line 153 of file test_multibytecodec_support.py.

00153 
00154     def test_callback_forward_index(self):
00155         def myreplace(exc):
00156             return ('REPLACED', exc.end + 2)
00157         codecs.register_error("test.cjktest", myreplace)
00158         self.assertEqual(self.encode('abcd' + self.unmappedunicode + 'efgh',
00159                                      'test.cjktest'), (b'abcdREPLACEDgh', 9))

Here is the call graph for this function:

Definition at line 160 of file test_multibytecodec_support.py.

00160 
00161     def test_callback_index_outofbound(self):
00162         def myreplace(exc):
00163             return ('TERM', 100)
00164         codecs.register_error("test.cjktest", myreplace)
00165         self.assertRaises(IndexError, self.encode, self.unmappedunicode,
00166                           'test.cjktest')

Here is the call graph for this function:

Definition at line 120 of file test_multibytecodec_support.py.

00120 
00121     def test_callback_long_index(self):
00122         def myreplace(exc):
00123             return ('x', int(exc.end))
00124         codecs.register_error("test.cjktest", myreplace)
00125         self.assertEqual(self.encode('abcd' + self.unmappedunicode + 'efgh',
00126                                      'test.cjktest'), (b'abcdxefgh', 9))
00127 
00128         def myreplace(exc):
00129             return ('x', sys.maxsize + 1)
00130         codecs.register_error("test.cjktest", myreplace)
00131         self.assertRaises(IndexError, self.encode, self.unmappedunicode,
00132                           'test.cjktest')

Here is the call graph for this function:

Definition at line 133 of file test_multibytecodec_support.py.

00133 
00134     def test_callback_None_index(self):
00135         def myreplace(exc):
00136             return ('x', None)
00137         codecs.register_error("test.cjktest", myreplace)
00138         self.assertRaises(TypeError, self.encode, self.unmappedunicode,
00139                           'test.cjktest')

Here is the call graph for this function:

Definition at line 111 of file test_multibytecodec_support.py.

00111 
00112     def test_callback_wrong_objects(self):
00113         def myreplace(exc):
00114             return (ret, exc.end)
00115         codecs.register_error("test.cjktest", myreplace)
00116 
00117         for ret in ([1, 2, 3], [], None, object(), b'string', b''):
00118             self.assertRaises(TypeError, self.encode, self.unmappedunicode,
00119                               'test.cjktest')

Here is the call graph for this function:

Reimplemented in test.test_codecencodings_iso2022.Test_ISO2022_KR.

Definition at line 37 of file test_multibytecodec_support.py.

00037 
00038     def test_chunkcoding(self):
00039         tstring_lines = []
00040         for b in self.tstring:
00041             lines = b.split(b"\n")
00042             last = lines.pop()
00043             assert last == b""
00044             lines = [line + b"\n" for line in lines]
00045             tstring_lines.append(lines)
00046         for native, utf8 in zip(*tstring_lines):
00047             u = self.decode(native)[0]
00048             self.assertEqual(u, utf8.decode('utf-8'))
00049             if self.roundtriptest:
00050                 self.assertEqual(native, self.encode(u)[0])

Here is the call graph for this function:

Definition at line 84 of file test_multibytecodec_support.py.

00084 
00085     def test_customreplace_encode(self):
00086         if self.has_iso10646:
00087             return
00088 
00089         from html.entities import codepoint2name
00090 
00091         def xmlcharnamereplace(exc):
00092             if not isinstance(exc, UnicodeEncodeError):
00093                 raise TypeError("don't know how to handle %r" % exc)
00094             l = []
00095             for c in exc.object[exc.start:exc.end]:
00096                 if ord(c) in codepoint2name:
00097                     l.append("&%s;" % codepoint2name[ord(c)])
00098                 else:
00099                     l.append("&#%d;" % ord(c))
00100             return ("".join(l), exc.end)
00101 
00102         codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace)
00103 
00104         if self.xmlcharnametest:
00105             sin, sout = self.xmlcharnametest
00106         else:
00107             sin = "\xab\u211c\xbb = \u2329\u1234\u232a"
00108             sout = b"«ℜ» = ⟨ሴ⟩"
00109         self.assertEqual(self.encode(sin,
00110                                     "test.xmlcharnamereplace")[0], sout)

Here is the call graph for this function:

Definition at line 51 of file test_multibytecodec_support.py.

00051 
00052     def test_errorhandle(self):
00053         for source, scheme, expected in self.codectests:
00054             if isinstance(source, bytes):
00055                 func = self.decode
00056             else:
00057                 func = self.encode
00058             if expected:
00059                 result = func(source, scheme)[0]
00060                 if func is self.decode:
00061                     self.assertTrue(type(result) is str, type(result))
00062                     self.assertEqual(result, expected,
00063                                      '%a.decode(%r, %r)=%a != %a'
00064                                      % (source, self.encoding, scheme, result,
00065                                         expected))
00066                 else:
00067                     self.assertTrue(type(result) is bytes, type(result))
00068                     self.assertEqual(result, expected,
00069                                      '%a.encode(%r, %r)=%a != %a'
00070                                      % (source, self.encoding, scheme, result,
00071                                         expected))
00072             else:
00073                 self.assertRaises(UnicodeError, func, source, scheme)

Here is the call graph for this function:

Definition at line 187 of file test_multibytecodec_support.py.

00187 
00188     def test_incrementaldecoder(self):
00189         UTF8Writer = codecs.getwriter('utf-8')
00190         for sizehint in [None, -1] + list(range(1, 33)) + \
00191                         [64, 128, 256, 512, 1024]:
00192             istream = BytesIO(self.tstring[0])
00193             ostream = UTF8Writer(BytesIO())
00194             decoder = self.incrementaldecoder()
00195             while 1:
00196                 data = istream.read(sizehint)
00197                 if not data:
00198                     break
00199                 else:
00200                     u = decoder.decode(data)
00201                     ostream.write(u)
00202 
00203             self.assertEqual(ostream.getvalue(), self.tstring[1])

Here is the call graph for this function:

Definition at line 167 of file test_multibytecodec_support.py.

00167 
00168     def test_incrementalencoder(self):
00169         UTF8Reader = codecs.getreader('utf-8')
00170         for sizehint in [None] + list(range(1, 33)) + \
00171                         [64, 128, 256, 512, 1024]:
00172             istream = UTF8Reader(BytesIO(self.tstring[1]))
00173             ostream = BytesIO()
00174             encoder = self.incrementalencoder()
00175             while 1:
00176                 if sizehint is not None:
00177                     data = istream.read(sizehint)
00178                 else:
00179                     data = istream.read()
00180 
00181                 if not data:
00182                     break
00183                 e = encoder.encode(data)
00184                 ostream.write(e)
00185 
00186             self.assertEqual(ostream.getvalue(), self.tstring[0])

Here is the call graph for this function:

Definition at line 204 of file test_multibytecodec_support.py.

00204 
00205     def test_incrementalencoder_error_callback(self):
00206         inv = self.unmappedunicode
00207 
00208         e = self.incrementalencoder()
00209         self.assertRaises(UnicodeEncodeError, e.encode, inv, True)
00210 
00211         e.errors = 'ignore'
00212         self.assertEqual(e.encode(inv, True), b'')
00213 
00214         e.reset()
00215         def tempreplace(exc):
00216             return ('called', exc.end)
00217         codecs.register_error('test.incremental_error_callback', tempreplace)
00218         e.errors = 'test.incremental_error_callback'
00219         self.assertEqual(e.encode(inv, True), b'called')
00220 
00221         # again
00222         e.errors = 'ignore'
00223         self.assertEqual(e.encode(inv, True), b'')

Here is the call graph for this function:

Definition at line 224 of file test_multibytecodec_support.py.

00224 
00225     def test_streamreader(self):
00226         UTF8Writer = codecs.getwriter('utf-8')
00227         for name in ["read", "readline", "readlines"]:
00228             for sizehint in [None, -1] + list(range(1, 33)) + \
00229                             [64, 128, 256, 512, 1024]:
00230                 istream = self.reader(BytesIO(self.tstring[0]))
00231                 ostream = UTF8Writer(BytesIO())
00232                 func = getattr(istream, name)
00233                 while 1:
00234                     data = func(sizehint)
00235                     if not data:
00236                         break
00237                     if name == "readlines":
00238                         ostream.writelines(data)
00239                     else:
00240                         ostream.write(data)
00241 
00242                 self.assertEqual(ostream.getvalue(), self.tstring[1])

Here is the call graph for this function:

Definition at line 243 of file test_multibytecodec_support.py.

00243 
00244     def test_streamwriter(self):
00245         readfuncs = ('read', 'readline', 'readlines')
00246         UTF8Reader = codecs.getreader('utf-8')
00247         for name in readfuncs:
00248             for sizehint in [None] + list(range(1, 33)) + \
00249                             [64, 128, 256, 512, 1024]:
00250                 istream = UTF8Reader(BytesIO(self.tstring[1]))
00251                 ostream = self.writer(BytesIO())
00252                 func = getattr(istream, name)
00253                 while 1:
00254                     if sizehint is not None:
00255                         data = func(sizehint)
00256                     else:
00257                         data = func()
00258 
00259                     if not data:
00260                         break
00261                     if name == "readlines":
00262                         ostream.writelines(data)
00263                     else:
00264                         ostream.write(data)
00265 
00266                 self.assertEqual(ostream.getvalue(), self.tstring[0])

Here is the call graph for this function:

Definition at line 74 of file test_multibytecodec_support.py.

00074 
00075     def test_xmlcharrefreplace(self):
00076         if self.has_iso10646:
00077             return
00078 
00079         s = "\u0b13\u0b23\u0b60 nd eggs"
00080         self.assertEqual(
00081             self.encode(s, "xmlcharrefreplace")[0],
00082             b"ଓଣୠ nd eggs"
00083         )

Here is the call graph for this function:


Member Data Documentation

Definition at line 18 of file test_multibytecodec_support.py.

Initial value:
(
        # invalid bytes
        (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"),

        # 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"),
    )

Reimplemented from test.test_multibytecodec_support.TestBase.

Definition at line 26 of file test_codecencodings_kr.py.

Definition at line 31 of file test_multibytecodec_support.py.

Definition at line 30 of file test_multibytecodec_support.py.

Reimplemented from test.test_multibytecodec_support.TestBase.

Definition at line 24 of file test_codecencodings_kr.py.

Reimplemented in test.test_codecencodings_cn.Test_GB18030.

Definition at line 23 of file test_multibytecodec_support.py.

Definition at line 35 of file test_multibytecodec_support.py.

Definition at line 34 of file test_multibytecodec_support.py.

Definition at line 32 of file test_multibytecodec_support.py.

Definition at line 22 of file test_multibytecodec_support.py.

Reimplemented from test.test_multibytecodec_support.TestBase.

Definition at line 25 of file test_codecencodings_kr.py.

Definition at line 25 of file test_multibytecodec_support.py.

Definition at line 33 of file test_multibytecodec_support.py.


The documentation for this class was generated from the following file: