Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_codeccallbacks.py @ 37850:ebe59cd18273
Use explicit relative import for an, ehm, relative import.
| author | Thomas Wouters <thomas@python.org> |
|---|---|
| date | Tue, 18 Apr 2006 21:41:36 +0000 |
| parents | e2473c4f2ee0 |
| children | 4c0823f0a0a1 |
| rev | line source |
|---|---|
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
1 import test.test_support, unittest |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
2 import sys, codecs, htmlentitydefs, unicodedata |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
3 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
4 class PosReturn: |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
5 # this can be used for configurable callbacks |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
6 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
7 def __init__(self): |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
8 self.pos = 0 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
9 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
10 def handle(self, exc): |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
11 oldpos = self.pos |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
12 realpos = oldpos |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
13 if realpos<0: |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27555
diff
changeset
|
14 realpos = len(exc.object) + realpos |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
15 # if we don't advance this time, terminate on the next call |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
16 # otherwise we'd get an endless loop |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
17 if realpos <= exc.start: |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
18 self.pos = len(exc.object) |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
19 return (u"<?>", oldpos) |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
20 |
|
35889
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
21 # A UnicodeEncodeError object without a start attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
22 class NoStartUnicodeEncodeError(UnicodeEncodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
23 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
24 UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
25 del self.start |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
26 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
27 # A UnicodeEncodeError object with a bad start attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
28 class BadStartUnicodeEncodeError(UnicodeEncodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
29 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
30 UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
31 self.start = [] |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
32 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
33 # A UnicodeEncodeError object without an end attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
34 class NoEndUnicodeEncodeError(UnicodeEncodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
35 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
36 UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
37 del self.end |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
38 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
39 # A UnicodeEncodeError object without an object attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
40 class NoObjectUnicodeEncodeError(UnicodeEncodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
41 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
42 UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
43 del self.object |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
44 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
45 # A UnicodeEncodeError object with a bad object attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
46 class BadObjectUnicodeEncodeError(UnicodeEncodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
47 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
48 UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
49 self.object = [] |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
50 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
51 # A UnicodeDecodeError object without an end attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
52 class NoEndUnicodeDecodeError(UnicodeDecodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
53 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
54 UnicodeDecodeError.__init__(self, "ascii", "", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
55 del self.end |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
56 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
57 # A UnicodeDecodeError object with a bad object attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
58 class BadObjectUnicodeDecodeError(UnicodeDecodeError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
59 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
60 UnicodeDecodeError.__init__(self, "ascii", "", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
61 self.object = [] |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
62 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
63 # A UnicodeTranslateError object without a start attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
64 class NoStartUnicodeTranslateError(UnicodeTranslateError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
65 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
66 UnicodeTranslateError.__init__(self, u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
67 del self.start |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
68 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
69 # A UnicodeTranslateError object without an end attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
70 class NoEndUnicodeTranslateError(UnicodeTranslateError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
71 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
72 UnicodeTranslateError.__init__(self, u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
73 del self.end |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
74 |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
75 # A UnicodeTranslateError object without an object attribute |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
76 class NoObjectUnicodeTranslateError(UnicodeTranslateError): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
77 def __init__(self): |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
78 UnicodeTranslateError.__init__(self, u"", 0, 1, "bad") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
79 del self.object |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
80 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
81 class CodecCallbackTest(unittest.TestCase): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
82 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
83 def test_xmlcharrefreplace(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
84 # replace unencodable characters which numeric character entities. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
85 # For ascii, latin-1 and charmaps this is completely implemented |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
86 # in C and should be reasonably fast. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
87 s = u"\u30b9\u30d1\u30e2 \xe4nd eggs" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
88 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
89 s.encode("ascii", "xmlcharrefreplace"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
90 "スパモ änd eggs" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
91 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
92 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
93 s.encode("latin-1", "xmlcharrefreplace"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
94 "スパモ \xe4nd eggs" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
95 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
96 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
97 def test_xmlcharnamereplace(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
98 # This time use a named character entity for unencodable |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
99 # characters, if one is available. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
100 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
101 def xmlcharnamereplace(exc): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
102 if not isinstance(exc, UnicodeEncodeError): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
103 raise TypeError("don't know how to handle %r" % exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
104 l = [] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
105 for c in exc.object[exc.start:exc.end]: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
106 try: |
|
28892
35c90d9cc313
Use the new htmlentitydefs.codepoint2name for test_xmlcharnamereplace()
Walter Dörwald <walter@livinglogic.de>
parents:
27963
diff
changeset
|
107 l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
108 except KeyError: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
109 l.append(u"&#%d;" % ord(c)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
110 return (u"".join(l), exc.end) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
111 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
112 codecs.register_error( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
113 "test.xmlcharnamereplace", xmlcharnamereplace) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
114 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
115 sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
116 sout = "«ℜ» = ⟨ሴ€⟩" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
117 self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
118 sout = "\xabℜ\xbb = ⟨ሴ€⟩" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
119 self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
120 sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
121 self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
122 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
123 def test_uninamereplace(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
124 # We're using the names from the unicode database this time, |
|
26405
b38533e01d65
Fix typo in comment.
Walter Dörwald <walter@livinglogic.de>
parents:
26378
diff
changeset
|
125 # and we're doing "syntax highlighting" here, i.e. we include |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
126 # the replaced text in ANSI escape sequences. For this it is |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
127 # useful that the error handler is not called for every single |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
128 # unencodable character, but for a complete sequence of |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
129 # unencodable characters, otherwise we would output many |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
130 # unneccessary escape sequences. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
131 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
132 def uninamereplace(exc): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
133 if not isinstance(exc, UnicodeEncodeError): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
134 raise TypeError("don't know how to handle %r" % exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
135 l = [] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
136 for c in exc.object[exc.start:exc.end]: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
137 l.append(unicodedata.name(c, u"0x%x" % ord(c))) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
138 return (u"\033[1m%s\033[0m" % u", ".join(l), exc.end) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
139 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
140 codecs.register_error( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
141 "test.uninamereplace", uninamereplace) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
142 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
143 sin = u"\xac\u1234\u20ac\u8000" |
|
26378
ab3763d477cc
Update character names.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
144 sout = "\033[1mNOT SIGN, ETHIOPIC SYLLABLE SEE, EURO SIGN, CJK UNIFIED IDEOGRAPH-8000\033[0m" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
145 self.assertEqual(sin.encode("ascii", "test.uninamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
146 |
|
26378
ab3763d477cc
Update character names.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
147 sout = "\xac\033[1mETHIOPIC SYLLABLE SEE, EURO SIGN, CJK UNIFIED IDEOGRAPH-8000\033[0m" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
148 self.assertEqual(sin.encode("latin-1", "test.uninamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
149 |
|
26378
ab3763d477cc
Update character names.
Martin v. Löwis <martin@v.loewis.de>
parents:
26128
diff
changeset
|
150 sout = "\xac\033[1mETHIOPIC SYLLABLE SEE\033[0m\xa4\033[1mCJK UNIFIED IDEOGRAPH-8000\033[0m" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
151 self.assertEqual(sin.encode("iso-8859-15", "test.uninamereplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
152 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
153 def test_backslashescape(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
154 # Does the same as the "unicode-escape" encoding, but with different |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
155 # base encodings. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
156 sin = u"a\xac\u1234\u20ac\u8000" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
157 if sys.maxunicode > 0xffff: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
158 sin += unichr(sys.maxunicode) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
159 sout = "a\\xac\\u1234\\u20ac\\u8000" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
160 if sys.maxunicode > 0xffff: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
161 sout += "\\U%08x" % sys.maxunicode |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
162 self.assertEqual(sin.encode("ascii", "backslashreplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
163 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
164 sout = "a\xac\\u1234\\u20ac\\u8000" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
165 if sys.maxunicode > 0xffff: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
166 sout += "\\U%08x" % sys.maxunicode |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
167 self.assertEqual(sin.encode("latin-1", "backslashreplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
168 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
169 sout = "a\xac\\u1234\xa4\\u8000" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
170 if sys.maxunicode > 0xffff: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
171 sout += "\\U%08x" % sys.maxunicode |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
172 self.assertEqual(sin.encode("iso-8859-15", "backslashreplace"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
173 |
| 35485 | 174 def test_decoderelaxedutf8(self): |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
175 # This is the test for a decoding callback handler, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
176 # that relaxes the UTF-8 minimal encoding restriction. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
177 # A null byte that is encoded as "\xc0\x80" will be |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
178 # decoded as a null byte. All other illegal sequences |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
179 # will be handled strictly. |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
180 def relaxedutf8(exc): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
181 if not isinstance(exc, UnicodeDecodeError): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
182 raise TypeError("don't know how to handle %r" % exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
183 if exc.object[exc.start:exc.end].startswith("\xc0\x80"): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
184 return (u"\x00", exc.start+2) # retry after two bytes |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
185 else: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
186 raise exc |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
187 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
188 codecs.register_error( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
189 "test.relaxedutf8", relaxedutf8) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
190 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
191 sin = "a\x00b\xc0\x80c\xc3\xbc\xc0\x80\xc0\x80" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
192 sout = u"a\x00b\x00c\xfc\x00\x00" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
193 self.assertEqual(sin.decode("utf-8", "test.relaxedutf8"), sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
194 sin = "\xc0\x80\xc0\x81" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
195 self.assertRaises(UnicodeError, sin.decode, "utf-8", "test.relaxedutf8") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
196 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
197 def test_charmapencode(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
198 # For charmap encodings the replacement string will be |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
199 # mapped through the encoding again. This means, that |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
200 # to be able to use e.g. the "replace" handler, the |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
201 # charmap has to have a mapping for "?". |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
202 charmap = dict([ (ord(c), 2*c.upper()) for c in "abcdefgh"]) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
203 sin = u"abc" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
204 sout = "AABBCC" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
205 self.assertEquals(codecs.charmap_encode(sin, "strict", charmap)[0], sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
206 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
207 sin = u"abcA" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
208 self.assertRaises(UnicodeError, codecs.charmap_encode, sin, "strict", charmap) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
209 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
210 charmap[ord("?")] = "XYZ" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
211 sin = u"abcDEF" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
212 sout = "AABBCCXYZXYZXYZ" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
213 self.assertEquals(codecs.charmap_encode(sin, "replace", charmap)[0], sout) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
214 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
215 charmap[ord("?")] = u"XYZ" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
216 self.assertRaises(TypeError, codecs.charmap_encode, sin, "replace", charmap) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
217 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
218 charmap[ord("?")] = u"XYZ" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
219 self.assertRaises(TypeError, codecs.charmap_encode, sin, "replace", charmap) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
220 |
| 35485 | 221 def test_decodeunicodeinternal(self): |
| 222 self.assertRaises( | |
| 223 UnicodeDecodeError, | |
| 224 "\x00\x00\x00\x00\x00".decode, | |
| 225 "unicode-internal", | |
| 226 ) | |
| 227 if sys.maxunicode > 0xffff: | |
| 228 def handler_unicodeinternal(exc): | |
| 229 if not isinstance(exc, UnicodeDecodeError): | |
| 230 raise TypeError("don't know how to handle %r" % exc) | |
| 231 return (u"\x01", 1) | |
| 232 | |
| 233 self.assertEqual( | |
| 234 "\x00\x00\x00\x00\x00".decode("unicode-internal", "ignore"), | |
| 235 u"\u0000" | |
| 236 ) | |
| 237 | |
| 238 self.assertEqual( | |
| 239 "\x00\x00\x00\x00\x00".decode("unicode-internal", "replace"), | |
| 240 u"\u0000\ufffd" | |
| 241 ) | |
| 242 | |
| 243 codecs.register_error("test.hui", handler_unicodeinternal) | |
| 244 | |
| 245 self.assertEqual( | |
| 246 "\x00\x00\x00\x00\x00".decode("unicode-internal", "test.hui"), | |
| 247 u"\u0000\u0001\u0000" | |
| 248 ) | |
| 249 | |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
250 def test_callbacks(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
251 def handler1(exc): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
252 if not isinstance(exc, UnicodeEncodeError) \ |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
253 and not isinstance(exc, UnicodeDecodeError): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
254 raise TypeError("don't know how to handle %r" % exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
255 l = [u"<%d>" % ord(exc.object[pos]) for pos in xrange(exc.start, exc.end)] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
256 return (u"[%s]" % u"".join(l), exc.end) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
257 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
258 codecs.register_error("test.handler1", handler1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
259 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
260 def handler2(exc): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
261 if not isinstance(exc, UnicodeDecodeError): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
262 raise TypeError("don't know how to handle %r" % exc) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
263 l = [u"<%d>" % ord(exc.object[pos]) for pos in xrange(exc.start, exc.end)] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
264 return (u"[%s]" % u"".join(l), exc.end+1) # skip one character |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
265 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
266 codecs.register_error("test.handler2", handler2) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
267 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
268 s = "\x00\x81\x7f\x80\xff" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
269 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
270 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
271 s.decode("ascii", "test.handler1"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
272 u"\x00[<129>]\x7f[<128>][<255>]" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
273 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
274 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
275 s.decode("ascii", "test.handler2"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
276 u"\x00[<129>][<128>]" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
277 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
278 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
279 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
280 "\\u3042\u3xxx".decode("unicode-escape", "test.handler1"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
281 u"\u3042[<92><117><51><120>]xx" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
282 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
283 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
284 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
285 "\\u3042\u3xx".decode("unicode-escape", "test.handler1"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
286 u"\u3042[<92><117><51><120><120>]" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
287 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
288 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
289 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
290 codecs.charmap_decode("abc", "test.handler1", {ord("a"): u"z"})[0], |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
291 u"z[<98>][<99>]" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
292 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
293 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
294 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
295 u"g\xfc\xdfrk".encode("ascii", "test.handler1"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
296 u"g[<252><223>]rk" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
297 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
298 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
299 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
300 u"g\xfc\xdf".encode("ascii", "test.handler1"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
301 u"g[<252><223>]" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
302 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
303 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
304 def test_longstrings(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
305 # test long strings to check for memory overflow problems |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
306 errors = [ "strict", "ignore", "replace", "xmlcharrefreplace", "backslashreplace"] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
307 # register the handlers under different names, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
308 # to prevent the codec from recognizing the name |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
309 for err in errors: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
310 codecs.register_error("test." + err, codecs.lookup_error(err)) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
311 l = 1000 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
312 errors += [ "test." + err for err in errors ] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
313 for uni in [ s*l for s in (u"x", u"\u3042", u"a\xe4") ]: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
314 for enc in ("ascii", "latin-1", "iso-8859-1", "iso-8859-15", "utf-8", "utf-7", "utf-16"): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
315 for err in errors: |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
316 try: |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
317 uni.encode(enc, err) |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
318 except UnicodeError: |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
319 pass |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
320 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
321 def check_exceptionobjectargs(self, exctype, args, msg): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
322 # Test UnicodeError subclasses: construction, attribute assignment and __str__ conversion |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
323 # check with one missing argument |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
324 self.assertRaises(TypeError, exctype, *args[:-1]) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
325 # check with one argument too much |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
326 self.assertRaises(TypeError, exctype, *(args + ["too much"])) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
327 # check with one argument of the wrong type |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
328 wrongargs = [ "spam", u"eggs", 42, 1.0, None ] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
329 for i in xrange(len(args)): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
330 for wrongarg in wrongargs: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
331 if type(wrongarg) is type(args[i]): |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
332 continue |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
333 # build argument array |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
334 callargs = [] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
335 for j in xrange(len(args)): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
336 if i==j: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
337 callargs.append(wrongarg) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
338 else: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
339 callargs.append(args[i]) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
340 self.assertRaises(TypeError, exctype, *callargs) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
341 |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
342 # check with the correct number and type of arguments |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
343 exc = exctype(*args) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
344 self.assertEquals(str(exc), msg) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
345 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
346 def test_unicodeencodeerror(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
347 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
348 UnicodeEncodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
349 ["ascii", u"g\xfcrk", 1, 2, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
350 "'ascii' codec can't encode character u'\\xfc' in position 1: ouch" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
351 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
352 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
353 UnicodeEncodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
354 ["ascii", u"g\xfcrk", 1, 4, "ouch"], |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
355 "'ascii' codec can't encode characters in position 1-3: ouch" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
356 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
357 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
358 UnicodeEncodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
359 ["ascii", u"\xfcx", 0, 1, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
360 "'ascii' codec can't encode character u'\\xfc' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
361 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
362 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
363 UnicodeEncodeError, |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
364 ["ascii", u"\u0100x", 0, 1, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
365 "'ascii' codec can't encode character u'\\u0100' in position 0: ouch" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
366 ) |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
367 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
368 UnicodeEncodeError, |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
369 ["ascii", u"\uffffx", 0, 1, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
370 "'ascii' codec can't encode character u'\\uffff' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
371 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
372 if sys.maxunicode > 0xffff: |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
373 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
374 UnicodeEncodeError, |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
375 ["ascii", u"\U00010000x", 0, 1, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
376 "'ascii' codec can't encode character u'\\U00010000' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
377 ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
378 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
379 def test_unicodedecodeerror(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
380 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
381 UnicodeDecodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
382 ["ascii", "g\xfcrk", 1, 2, "ouch"], |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
383 "'ascii' codec can't decode byte 0xfc in position 1: ouch" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
384 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
385 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
386 UnicodeDecodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
387 ["ascii", "g\xfcrk", 1, 3, "ouch"], |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
388 "'ascii' codec can't decode bytes in position 1-2: ouch" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
389 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
390 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
391 def test_unicodetranslateerror(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
392 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
393 UnicodeTranslateError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
394 [u"g\xfcrk", 1, 2, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
395 "can't translate character u'\\xfc' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
396 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
397 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
398 UnicodeTranslateError, |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
399 [u"g\u0100rk", 1, 2, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
400 "can't translate character u'\\u0100' in position 1: ouch" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
401 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
402 self.check_exceptionobjectargs( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
403 UnicodeTranslateError, |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
404 [u"g\uffffrk", 1, 2, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
405 "can't translate character u'\\uffff' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
406 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
407 if sys.maxunicode > 0xffff: |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
408 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
409 UnicodeTranslateError, |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
410 [u"g\U00010000rk", 1, 2, "ouch"], |
|
30138
f746d5690ad6
Add a unicode prefix to the characters in the UnicodeEncodeError and
Walter Dörwald <walter@livinglogic.de>
parents:
30137
diff
changeset
|
411 "can't translate character u'\\U00010000' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
412 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
413 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
414 UnicodeTranslateError, |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
415 [u"g\xfcrk", 1, 3, "ouch"], |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
416 "can't translate characters in position 1-2: ouch" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
417 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
418 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
419 def test_badandgoodstrictexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
420 # "strict" complains about a non-exception passed in |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
421 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
422 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
423 codecs.strict_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
424 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
425 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
426 # "strict" complains about the wrong exception type |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
427 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
428 Exception, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
429 codecs.strict_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
430 Exception("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
431 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
432 |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
433 # If the correct exception is passed in, "strict" raises it |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
434 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
435 UnicodeEncodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
436 codecs.strict_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
437 UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
438 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
439 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
440 def test_badandgoodignoreexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
441 # "ignore" complains about a non-exception passed in |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
442 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
443 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
444 codecs.ignore_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
445 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
446 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
447 # "ignore" complains about the wrong exception type |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
448 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
449 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
450 codecs.ignore_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
451 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
452 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
453 # If the correct exception is passed in, "ignore" returns an empty replacement |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
454 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
455 codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
456 (u"", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
457 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
458 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
459 codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
460 (u"", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
461 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
462 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
463 codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
464 (u"", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
465 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
466 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
467 def test_badandgoodreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
468 # "replace" complains about a non-exception passed in |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
469 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
470 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
471 codecs.replace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
472 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
473 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
474 # "replace" complains about the wrong exception type |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
475 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
476 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
477 codecs.replace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
478 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
479 ) |
|
35889
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
480 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
481 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
482 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
483 NoStartUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
484 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
485 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
486 TypeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
487 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
488 BadStartUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
489 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
490 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
491 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
492 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
493 NoEndUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
494 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
495 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
496 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
497 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
498 NoObjectUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
499 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
500 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
501 TypeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
502 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
503 BadObjectUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
504 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
505 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
506 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
507 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
508 NoEndUnicodeDecodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
509 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
510 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
511 TypeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
512 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
513 BadObjectUnicodeDecodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
514 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
515 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
516 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
517 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
518 NoStartUnicodeTranslateError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
519 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
520 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
521 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
522 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
523 NoEndUnicodeTranslateError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
524 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
525 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
526 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
527 codecs.replace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
528 NoObjectUnicodeTranslateError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
529 ) |
|
34166
e53693a02cf0
Fix copy & paste error in comments.
Walter Dörwald <walter@livinglogic.de>
parents:
31389
diff
changeset
|
530 # With the correct exception, "replace" returns an "?" or u"\ufffd" replacement |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
531 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
532 codecs.replace_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
533 (u"?", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
534 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
535 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
536 codecs.replace_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
537 (u"\ufffd", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
538 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
539 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
540 codecs.replace_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
541 (u"\ufffd", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
542 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
543 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
544 def test_badandgoodxmlcharrefreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
545 # "xmlcharrefreplace" complains about a non-exception passed in |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
546 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
547 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
548 codecs.xmlcharrefreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
549 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
550 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
551 # "xmlcharrefreplace" complains about the wrong exception types |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
552 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
553 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
554 codecs.xmlcharrefreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
555 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
556 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
557 # "xmlcharrefreplace" can only be used for encoding |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
558 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
559 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
560 codecs.xmlcharrefreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
561 UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
562 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
563 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
564 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
565 codecs.xmlcharrefreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
566 UnicodeTranslateError(u"\u3042", 0, 1, "ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
567 ) |
|
35889
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
568 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
569 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
570 codecs.xmlcharrefreplace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
571 NoStartUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
572 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
573 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
574 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
575 codecs.xmlcharrefreplace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
576 NoEndUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
577 ) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
578 self.assertRaises( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
579 AttributeError, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
580 codecs.xmlcharrefreplace_errors, |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
581 NoObjectUnicodeEncodeError() |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
582 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
583 # Use the correct exception |
|
35889
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
584 cs = (0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 0x3042) |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
585 s = "".join(unichr(c) for c in cs) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
586 self.assertEquals( |
|
35889
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
587 codecs.xmlcharrefreplace_errors( |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
588 UnicodeEncodeError("ascii", s, 0, len(s), "ouch") |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
589 ), |
|
e2473c4f2ee0
Add tests to increase code coverage in Python/codecs.c and Python/exceptions.c.
Walter Dörwald <walter@livinglogic.de>
parents:
35882
diff
changeset
|
590 (u"".join(u"&#%d;" % ord(c) for c in s), len(s)) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
591 ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
592 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
593 def test_badandgoodbackslashreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
594 # "backslashreplace" complains about a non-exception passed in |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
595 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
596 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
597 codecs.backslashreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
598 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
599 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
600 # "backslashreplace" complains about the wrong exception types |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
601 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
602 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
603 codecs.backslashreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
604 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
605 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
606 # "backslashreplace" can only be used for encoding |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
607 self.assertRaises( |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
608 TypeError, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
609 codecs.backslashreplace_errors, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
610 UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch") |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
611 ) |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
612 self.assertRaises( |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
613 TypeError, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
614 codecs.backslashreplace_errors, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
615 UnicodeTranslateError(u"\u3042", 0, 1, "ouch") |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
616 ) |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
617 # Use the correct exception |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
618 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
619 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
620 (u"\\u3042", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
621 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
622 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
623 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\x00", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
624 (u"\\x00", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
625 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
626 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
627 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\xff", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
628 (u"\\xff", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
629 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
630 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
631 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\u0100", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
632 (u"\\u0100", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
633 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
634 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
635 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\uffff", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
636 (u"\\uffff", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
637 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
638 if sys.maxunicode>0xffff: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
639 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
640 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\U00010000", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
641 (u"\\U00010000", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
642 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
643 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
644 codecs.backslashreplace_errors(UnicodeEncodeError("ascii", u"\U0010ffff", 0, 1, "ouch")), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
645 (u"\\U0010ffff", 1) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
646 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
647 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
648 def test_badhandlerresults(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
649 results = ( 42, u"foo", (1,2,3), (u"foo", 1, 3), (u"foo", None), (u"foo",), ("foo", 1, 3), ("foo", None), ("foo",) ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
650 encs = ("ascii", "latin-1", "iso-8859-1", "iso-8859-15") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
651 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
652 for res in results: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
653 codecs.register_error("test.badhandler", lambda: res) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
654 for enc in encs: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
655 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
656 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
657 u"\u3042".encode, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
658 enc, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
659 "test.badhandler" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
660 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
661 for (enc, bytes) in ( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
662 ("ascii", "\xff"), |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
663 ("utf-8", "\xff"), |
| 35485 | 664 ("utf-7", "+x-"), |
| 665 ("unicode-internal", "\x00"), | |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
666 ): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
667 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
668 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
669 bytes.decode, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
670 enc, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
671 "test.badhandler" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
672 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
673 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
674 def test_lookup(self): |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
675 self.assertEquals(codecs.strict_errors, codecs.lookup_error("strict")) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
676 self.assertEquals(codecs.ignore_errors, codecs.lookup_error("ignore")) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
677 self.assertEquals(codecs.strict_errors, codecs.lookup_error("strict")) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
678 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
679 codecs.xmlcharrefreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
680 codecs.lookup_error("xmlcharrefreplace") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
681 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
682 self.assertEquals( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
683 codecs.backslashreplace_errors, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
684 codecs.lookup_error("backslashreplace") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
685 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
686 |
|
25139
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
687 def test_unencodablereplacement(self): |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
688 def unencrepl(exc): |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
689 if isinstance(exc, UnicodeEncodeError): |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
690 return (u"\u4242", exc.end) |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
691 else: |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
692 raise TypeError("don't know how to handle %r" % exc) |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
693 codecs.register_error("test.unencreplhandler", unencrepl) |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
694 for enc in ("ascii", "iso-8859-1", "iso-8859-15"): |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
695 self.assertRaises( |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
696 UnicodeEncodeError, |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
697 u"\u4242".encode, |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
698 enc, |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
699 "test.unencreplhandler" |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
700 ) |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
701 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
702 def test_badregistercall(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
703 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
704 # Modules/_codecsmodule.c::register_error() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
705 # Python/codecs.c::PyCodec_RegisterError() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
706 self.assertRaises(TypeError, codecs.register_error, 42) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
707 self.assertRaises(TypeError, codecs.register_error, "test.dummy", 42) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
708 |
|
35882
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
709 def test_badlookupcall(self): |
|
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
710 # enhance coverage of: |
|
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
711 # Modules/_codecsmodule.c::lookup_error() |
|
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
712 self.assertRaises(TypeError, codecs.lookup_error) |
|
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
713 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
714 def test_unknownhandler(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
715 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
716 # Modules/_codecsmodule.c::lookup_error() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
717 self.assertRaises(LookupError, codecs.lookup_error, "test.unknown") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
718 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
719 def test_xmlcharrefvalues(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
720 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
721 # Python/codecs.c::PyCodec_XMLCharRefReplaceErrors() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
722 # and inline implementations |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
723 v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000) |
|
27183
01d9fd595375
Make the test scripts work again with narrow Python builds.
Walter Dörwald <walter@livinglogic.de>
parents:
27177
diff
changeset
|
724 if sys.maxunicode>=100000: |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27555
diff
changeset
|
725 v += (100000, 500000, 1000000) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
726 s = u"".join([unichr(x) for x in v]) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
727 codecs.register_error("test.xmlcharrefreplace", codecs.xmlcharrefreplace_errors) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
728 for enc in ("ascii", "iso-8859-15"): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
729 for err in ("xmlcharrefreplace", "test.xmlcharrefreplace"): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
730 s.encode(enc, err) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
731 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
732 def test_decodehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
733 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
734 # Objects/unicodeobject.c::unicode_decode_call_errorhandler() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
735 # and callers |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
736 self.assertRaises(LookupError, "\xff".decode, "ascii", "test.unknown") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
737 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
738 def baddecodereturn1(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
739 return 42 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
740 codecs.register_error("test.baddecodereturn1", baddecodereturn1) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
741 self.assertRaises(TypeError, "\xff".decode, "ascii", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
742 self.assertRaises(TypeError, "\\".decode, "unicode-escape", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
743 self.assertRaises(TypeError, "\\x0".decode, "unicode-escape", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
744 self.assertRaises(TypeError, "\\x0y".decode, "unicode-escape", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
745 self.assertRaises(TypeError, "\\Uffffeeee".decode, "unicode-escape", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
746 self.assertRaises(TypeError, "\\uyyyy".decode, "raw-unicode-escape", "test.baddecodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
747 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
748 def baddecodereturn2(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
749 return (u"?", None) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
750 codecs.register_error("test.baddecodereturn2", baddecodereturn2) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
751 self.assertRaises(TypeError, "\xff".decode, "ascii", "test.baddecodereturn2") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
752 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
753 handler = PosReturn() |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
754 codecs.register_error("test.posreturn", handler.handle) |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
755 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
756 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
757 handler.pos = -1 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
758 self.assertEquals("\xff0".decode("ascii", "test.posreturn"), u"<?>0") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
759 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
760 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
761 handler.pos = -2 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
762 self.assertEquals("\xff0".decode("ascii", "test.posreturn"), u"<?><?>") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
763 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
764 # Negative position out of bounds |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
765 handler.pos = -3 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
766 self.assertRaises(IndexError, "\xff0".decode, "ascii", "test.posreturn") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
767 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
768 # Valid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
769 handler.pos = 1 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
770 self.assertEquals("\xff0".decode("ascii", "test.posreturn"), u"<?>0") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
771 |
|
34166
e53693a02cf0
Fix copy & paste error in comments.
Walter Dörwald <walter@livinglogic.de>
parents:
31389
diff
changeset
|
772 # Largest valid positive position (one beyond end of input) |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
773 handler.pos = 2 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
774 self.assertEquals("\xff0".decode("ascii", "test.posreturn"), u"<?>") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
775 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
776 # Invalid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
777 handler.pos = 3 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
778 self.assertRaises(IndexError, "\xff0".decode, "ascii", "test.posreturn") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
779 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
780 # Restart at the "0" |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
781 handler.pos = 6 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
782 self.assertEquals("\\uyyyy0".decode("raw-unicode-escape", "test.posreturn"), u"<?>0") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
783 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
784 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
785 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
786 raise ValueError |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
787 self.assertRaises(UnicodeError, codecs.charmap_decode, "\xff", "strict", {0xff: None}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
788 self.assertRaises(ValueError, codecs.charmap_decode, "\xff", "strict", D()) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
789 self.assertRaises(TypeError, codecs.charmap_decode, "\xff", "strict", {0xff: sys.maxunicode+1}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
790 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
791 def test_encodehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
792 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
793 # Objects/unicodeobject.c::unicode_encode_call_errorhandler() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
794 # and callers |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
795 self.assertRaises(LookupError, u"\xff".encode, "ascii", "test.unknown") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
796 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
797 def badencodereturn1(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
798 return 42 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
799 codecs.register_error("test.badencodereturn1", badencodereturn1) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
800 self.assertRaises(TypeError, u"\xff".encode, "ascii", "test.badencodereturn1") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
801 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
802 def badencodereturn2(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
803 return (u"?", None) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
804 codecs.register_error("test.badencodereturn2", badencodereturn2) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
805 self.assertRaises(TypeError, u"\xff".encode, "ascii", "test.badencodereturn2") |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
806 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
807 handler = PosReturn() |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
808 codecs.register_error("test.posreturn", handler.handle) |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
809 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
810 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
811 handler.pos = -1 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
812 self.assertEquals(u"\xff0".encode("ascii", "test.posreturn"), "<?>0") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
813 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
814 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
815 handler.pos = -2 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
816 self.assertEquals(u"\xff0".encode("ascii", "test.posreturn"), "<?><?>") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
817 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
818 # Negative position out of bounds |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
819 handler.pos = -3 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
820 self.assertRaises(IndexError, u"\xff0".encode, "ascii", "test.posreturn") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
821 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
822 # Valid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
823 handler.pos = 1 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
824 self.assertEquals(u"\xff0".encode("ascii", "test.posreturn"), "<?>0") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
825 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
826 # Largest valid positive position (one beyond end of input |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
827 handler.pos = 2 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
828 self.assertEquals(u"\xff0".encode("ascii", "test.posreturn"), "<?>") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
829 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
830 # Invalid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
831 handler.pos = 3 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
832 self.assertRaises(IndexError, u"\xff0".encode, "ascii", "test.posreturn") |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
833 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
834 handler.pos = 0 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
835 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
836 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
837 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
838 raise ValueError |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
839 for err in ("strict", "replace", "xmlcharrefreplace", "backslashreplace", "test.posreturn"): |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
840 self.assertRaises(UnicodeError, codecs.charmap_encode, u"\xff", err, {0xff: None}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
841 self.assertRaises(ValueError, codecs.charmap_encode, u"\xff", err, D()) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
842 self.assertRaises(TypeError, codecs.charmap_encode, u"\xff", err, {0xff: 300}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
843 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
844 def test_translatehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
845 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
846 # Objects/unicodeobject.c::unicode_encode_call_errorhandler() |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
847 # and callers |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
848 # (Unfortunately the errors argument is not directly accessible |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
849 # from Python, so we can't test that much) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
850 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
851 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
852 raise ValueError |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
853 self.assertRaises(ValueError, u"\xff".translate, D()) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
854 self.assertRaises(TypeError, u"\xff".translate, {0xff: sys.maxunicode+1}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
855 self.assertRaises(TypeError, u"\xff".translate, {0xff: ()}) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
856 |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
857 def test_bug828737(self): |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
858 charmap = { |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
859 ord("&"): u"&", |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
860 ord("<"): u"<", |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
861 ord(">"): u">", |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
862 ord('"'): u""", |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
863 } |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30765
diff
changeset
|
864 |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
865 for n in (1, 10, 100, 1000): |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
866 text = u'abc<def>ghi'*n |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
867 text.translate(charmap) |
|
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
868 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
869 def test_main(): |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28892
diff
changeset
|
870 test.test_support.run_unittest(CodecCallbackTest) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
871 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
872 if __name__ == "__main__": |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
873 test_main() |
