Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_codeccallbacks.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 05f7883ee92d |
| children |
| rev | line source |
|---|---|
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
1 import codecs |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
2 import html.entities |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
3 import sys |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
4 import test.support |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
5 import unicodedata |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
6 import unittest |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
7 import warnings |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
8 |
|
72683
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
9 try: |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
10 import ctypes |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
11 except ImportError: |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
12 ctypes = None |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
13 SIZEOF_WCHAR_T = -1 |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
14 else: |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
15 SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
16 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
17 class PosReturn: |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
18 # 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
|
19 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
20 def __init__(self): |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
21 self.pos = 0 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
22 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
23 def handle(self, exc): |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
24 oldpos = self.pos |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
25 realpos = oldpos |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
26 if realpos<0: |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27555
diff
changeset
|
27 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
|
28 # 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
|
29 # 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
|
30 if realpos <= exc.start: |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
31 self.pos = len(exc.object) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
32 return ("<?>", oldpos) |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
33 |
|
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
|
34 # 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
|
35 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
|
36 def __init__(self): |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
37 UnicodeEncodeError.__init__(self, "ascii", "", 0, 1, "bad") |
|
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
|
38 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
|
39 |
|
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 # 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
|
41 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
|
42 def __init__(self): |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
43 UnicodeEncodeError.__init__(self, "ascii", "", 0, 1, "bad") |
|
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
|
44 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
|
45 |
|
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 # 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
|
47 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
|
48 def __init__(self): |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
49 UnicodeDecodeError.__init__(self, "ascii", bytearray(b""), 0, 1, "bad") |
|
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
|
50 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
|
51 |
|
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 # 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
|
53 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
|
54 def __init__(self): |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
55 UnicodeDecodeError.__init__(self, "ascii", bytearray(b""), 0, 1, "bad") |
|
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
|
56 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
|
57 |
|
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 # 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
|
59 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
|
60 def __init__(self): |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
61 UnicodeTranslateError.__init__(self, "", 0, 1, "bad") |
|
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
|
62 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
|
63 |
|
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 # 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
|
65 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
|
66 def __init__(self): |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
67 UnicodeTranslateError.__init__(self, "", 0, 1, "bad") |
|
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
|
68 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
|
69 |
|
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 # 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
|
71 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
|
72 def __init__(self): |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
73 UnicodeTranslateError.__init__(self, "", 0, 1, "bad") |
|
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
|
74 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
|
75 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
76 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
|
77 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
78 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
|
79 # 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
|
80 # 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
|
81 # in C and should be reasonably fast. |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
82 s = "\u30b9\u30d1\u30e2 \xe4nd eggs" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
83 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
84 s.encode("ascii", "xmlcharrefreplace"), |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
85 b"スパモ änd eggs" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
86 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
87 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
88 s.encode("latin-1", "xmlcharrefreplace"), |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
89 b"スパモ \xe4nd eggs" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
90 ) |
|
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 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
|
93 # 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
|
94 # 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
|
95 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 l = [] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
100 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
|
101 try: |
|
47147
7296a2fb4786
rename HTMLParser to html.parser and htmlentitydefs to html.entities;
Fred Drake <fdrake@acm.org>
parents:
43947
diff
changeset
|
102 l.append("&%s;" % html.entities.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
|
103 except KeyError: |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
104 l.append("&#%d;" % ord(c)) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
105 return ("".join(l), exc.end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
106 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
107 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
|
108 "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
|
109 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
110 sin = "\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
111 sout = b"«ℜ» = ⟨ሴ€⟩" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
112 self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
113 sout = b"\xabℜ\xbb = ⟨ሴ€⟩" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
114 self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
115 sout = b"\xabℜ\xbb = ⟨ሴ\xa4⟩" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
116 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
|
117 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
118 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
|
119 # 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
|
120 # 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
|
121 # 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
|
122 # 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
|
123 # 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
|
124 # unencodable characters, otherwise we would output many |
|
51776
d06a3ebf306f
Merged revisions 69846 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50886
diff
changeset
|
125 # unnecessary escape sequences. |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
126 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 l = [] |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
131 for c in exc.object[exc.start:exc.end]: |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
132 l.append(unicodedata.name(c, "0x%x" % ord(c))) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
133 return ("\033[1m%s\033[0m" % ", ".join(l), exc.end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
134 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
135 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
|
136 "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
|
137 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
138 sin = "\xac\u1234\u20ac\u8000" |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
139 sout = b"\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
|
140 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
|
141 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
142 sout = b"\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
|
143 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
|
144 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
145 sout = b"\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
|
146 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
|
147 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
148 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
|
149 # 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
|
150 # base encodings. |
|
72666
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72535
diff
changeset
|
151 sin = "a\xac\u1234\u20ac\u8000\U0010ffff" |
|
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72535
diff
changeset
|
152 sout = b"a\\xac\\u1234\\u20ac\\u8000\\U0010ffff" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
153 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
|
154 |
|
72666
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72535
diff
changeset
|
155 sout = b"a\xac\\u1234\\u20ac\\u8000\\U0010ffff" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
156 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
|
157 |
|
72666
f39b26ca7f3d
#13054: fix usage of sys.maxunicode after PEP-393.
Ezio Melotti
parents:
72535
diff
changeset
|
158 sout = b"a\xac\\u1234\xa4\\u8000\\U0010ffff" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
159 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
|
160 |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
161 def test_decoding_callbacks(self): |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
162 # This is a test for a decoding callback handler |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
163 # that allows the decoding of the invalid sequence |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
164 # "\xc0\x80" and returns "\x00" instead of raising an error. |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
165 # All other illegal sequences will be handled strictly. |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
166 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
|
167 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
|
168 raise TypeError("don't know how to handle %r" % exc) |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
169 if exc.object[exc.start:exc.start+2] == b"\xc0\x80": |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
170 return ("\x00", exc.start+2) # retry after two bytes |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
171 else: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
172 raise exc |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
173 |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
174 codecs.register_error("test.relaxedutf8", relaxedutf8) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
175 |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
176 # all the "\xc0\x80" will be decoded to "\x00" |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
177 sin = b"a\x00b\xc0\x80c\xc3\xbc\xc0\x80\xc0\x80" |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
178 sout = "a\x00b\x00c\xfc\x00\x00" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
179 self.assertEqual(sin.decode("utf-8", "test.relaxedutf8"), sout) |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
180 |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
181 # "\xc0\x81" is not valid and a UnicodeDecodeError will be raised |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
182 sin = b"\xc0\x80\xc0\x81" |
|
62665
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
183 self.assertRaises(UnicodeDecodeError, sin.decode, |
|
e0d5a4a49112
Update PyUnicode_DecodeUTF8 from RFC 2279 to RFC 3629.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
51776
diff
changeset
|
184 "utf-8", "test.relaxedutf8") |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
185 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
186 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
|
187 # 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
|
188 # 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
|
189 # 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
|
190 # charmap has to have a mapping for "?". |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43673
diff
changeset
|
191 charmap = dict((ord(c), bytes(2*c.upper(), 'ascii')) for c in "abcdefgh") |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
192 sin = "abc" |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
193 sout = b"AABBCC" |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
194 self.assertEqual(codecs.charmap_encode(sin, "strict", charmap)[0], sout) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
195 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
196 sin = "abcA" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
197 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
|
198 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43673
diff
changeset
|
199 charmap[ord("?")] = b"XYZ" |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
200 sin = "abcDEF" |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
201 sout = b"AABBCCXYZXYZXYZ" |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
202 self.assertEqual(codecs.charmap_encode(sin, "replace", charmap)[0], sout) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
203 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
204 charmap[ord("?")] = "XYZ" # wrong type in mapping |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
205 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
|
206 |
| 35485 | 207 def test_decodeunicodeinternal(self): |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
208 with test.support.check_warnings(('unicode_internal codec has been ' |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
209 'deprecated', DeprecationWarning)): |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
210 self.assertRaises( |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
211 UnicodeDecodeError, |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
212 b"\x00\x00\x00\x00\x00".decode, |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
213 "unicode-internal", |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
214 ) |
|
72535
7a50e549bd11
Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72475
diff
changeset
|
215 if SIZEOF_WCHAR_T == 4: |
| 35485 | 216 def handler_unicodeinternal(exc): |
| 217 if not isinstance(exc, UnicodeDecodeError): | |
| 218 raise TypeError("don't know how to handle %r" % exc) | |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
219 return ("\x01", 1) |
| 35485 | 220 |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
221 with test.support.check_warnings(('unicode_internal codec has been ' |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
222 'deprecated', DeprecationWarning)): |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
223 self.assertEqual( |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
224 b"\x00\x00\x00\x00\x00".decode("unicode-internal", "ignore"), |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
225 "\u0000" |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
226 ) |
| 35485 | 227 |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
228 self.assertEqual( |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
229 b"\x00\x00\x00\x00\x00".decode("unicode-internal", "replace"), |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
230 "\u0000\ufffd" |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
231 ) |
| 35485 | 232 |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
233 codecs.register_error("test.hui", handler_unicodeinternal) |
| 35485 | 234 |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
235 self.assertEqual( |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
236 b"\x00\x00\x00\x00\x00".decode("unicode-internal", "test.hui"), |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
237 "\u0000\u0001\u0000" |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
238 ) |
| 35485 | 239 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
240 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
|
241 def handler1(exc): |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
242 r = range(exc.start, exc.end) |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
243 if isinstance(exc, UnicodeEncodeError): |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
244 l = ["<%d>" % ord(exc.object[pos]) for pos in r] |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
245 elif isinstance(exc, UnicodeDecodeError): |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
246 l = ["<%d>" % exc.object[pos] for pos in r] |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
247 else: |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
248 raise TypeError("don't know how to handle %r" % exc) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
249 return ("[%s]" % "".join(l), exc.end) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
250 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
251 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
|
252 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
253 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
|
254 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
|
255 raise TypeError("don't know how to handle %r" % exc) |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
256 l = ["<%d>" % exc.object[pos] for pos in range(exc.start, exc.end)] |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
257 return ("[%s]" % "".join(l), exc.end+1) # skip one character |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
258 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
259 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
|
260 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
261 s = b"\x00\x81\x7f\x80\xff" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
262 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
263 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
264 s.decode("ascii", "test.handler1"), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
265 "\x00[<129>]\x7f[<128>][<255>]" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
266 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
267 self.assertEqual( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
268 s.decode("ascii", "test.handler2"), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
269 "\x00[<129>][<128>]" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
270 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
271 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
272 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
273 b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1"), |
|
81804
084bec5443d6
Issue #16979: Fix error handling bugs in the unicode-escape-decode decoder.
Serhiy Storchaka <storchaka@gmail.com>
parents:
79107
diff
changeset
|
274 "\u3042[<92><117><51>]xxx" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
275 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
276 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
277 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
278 b"\\u3042\u3xx".decode("unicode-escape", "test.handler1"), |
|
81804
084bec5443d6
Issue #16979: Fix error handling bugs in the unicode-escape-decode decoder.
Serhiy Storchaka <storchaka@gmail.com>
parents:
79107
diff
changeset
|
279 "\u3042[<92><117><51>]xx" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
280 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
281 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
282 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
283 codecs.charmap_decode(b"abc", "test.handler1", {ord("a"): "z"})[0], |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
284 "z[<98>][<99>]" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
285 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
286 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
287 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
288 "g\xfc\xdfrk".encode("ascii", "test.handler1"), |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
289 b"g[<252><223>]rk" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
290 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
291 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
292 self.assertEqual( |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
293 "g\xfc\xdf".encode("ascii", "test.handler1"), |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
294 b"g[<252><223>]" |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
295 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
296 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
297 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
|
298 # test long strings to check for memory overflow problems |
|
42626
f1a2d51f1cab
Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents:
42408
diff
changeset
|
299 errors = [ "strict", "ignore", "replace", "xmlcharrefreplace", |
|
f1a2d51f1cab
Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents:
42408
diff
changeset
|
300 "backslashreplace"] |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
301 # 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
|
302 # 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
|
303 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
|
304 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
|
305 l = 1000 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
306 errors += [ "test." + err for err in errors ] |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
307 for uni in [ s*l for s in ("x", "\u3042", "a\xe4") ]: |
|
42626
f1a2d51f1cab
Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents:
42408
diff
changeset
|
308 for enc in ("ascii", "latin-1", "iso-8859-1", "iso-8859-15", |
|
f1a2d51f1cab
Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents:
42408
diff
changeset
|
309 "utf-8", "utf-7", "utf-16", "utf-32"): |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
310 for err in errors: |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
311 try: |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
312 uni.encode(enc, err) |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
313 except UnicodeError: |
|
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
314 pass |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
315 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
316 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
|
317 # 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
|
318 # 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
|
319 self.assertRaises(TypeError, exctype, *args[:-1]) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
320 # 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
|
321 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
|
322 # check with one argument of the wrong type |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43673
diff
changeset
|
323 wrongargs = [ "spam", b"eggs", b"spam", 42, 1.0, None ] |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41585
diff
changeset
|
324 for i in range(len(args)): |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
325 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
|
326 if type(wrongarg) is type(args[i]): |
|
26128
23ef7c163a12
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
25139
diff
changeset
|
327 continue |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
328 # 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
|
329 callargs = [] |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41585
diff
changeset
|
330 for j in range(len(args)): |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
331 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
|
332 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
|
333 else: |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
334 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
|
335 self.assertRaises(TypeError, exctype, *callargs) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
336 |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
337 # 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
|
338 exc = exctype(*args) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
339 self.assertEqual(str(exc), msg) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
340 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
341 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
|
342 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
|
343 UnicodeEncodeError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
344 ["ascii", "g\xfcrk", 1, 2, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
345 "'ascii' codec can't encode character '\\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
|
346 ) |
|
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, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
349 ["ascii", "g\xfcrk", 1, 4, "ouch"], |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
350 "'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
|
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, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
354 ["ascii", "\xfcx", 0, 1, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
355 "'ascii' codec can't encode character '\\xfc' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
356 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
357 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
358 UnicodeEncodeError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
359 ["ascii", "\u0100x", 0, 1, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
360 "'ascii' codec can't encode character '\\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
|
361 ) |
|
30137
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, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
364 ["ascii", "\uffffx", 0, 1, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
365 "'ascii' codec can't encode character '\\uffff' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
366 ) |
|
72535
7a50e549bd11
Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72475
diff
changeset
|
367 if SIZEOF_WCHAR_T == 4: |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
368 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
369 UnicodeEncodeError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
370 ["ascii", "\U00010000x", 0, 1, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
371 "'ascii' codec can't encode character '\\U00010000' in position 0: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
372 ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
373 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
374 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
|
375 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
|
376 UnicodeDecodeError, |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
377 ["ascii", bytearray(b"g\xfcrk"), 1, 2, "ouch"], |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
378 "'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
|
379 ) |
|
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, |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
382 ["ascii", bytearray(b"g\xfcrk"), 1, 3, "ouch"], |
|
25091
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 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
|
384 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
385 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
386 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
|
387 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
|
388 UnicodeTranslateError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
389 ["g\xfcrk", 1, 2, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
390 "can't translate character '\\xfc' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
391 ) |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
392 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
393 UnicodeTranslateError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
394 ["g\u0100rk", 1, 2, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
395 "can't translate character '\\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
|
396 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
397 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
|
398 UnicodeTranslateError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
399 ["g\uffffrk", 1, 2, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
400 "can't translate character '\\uffff' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
401 ) |
|
72535
7a50e549bd11
Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72475
diff
changeset
|
402 if SIZEOF_WCHAR_T == 4: |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
403 self.check_exceptionobjectargs( |
|
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
404 UnicodeTranslateError, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
405 ["g\U00010000rk", 1, 2, "ouch"], |
|
42118
70a0831feda6
Patch by Ron Adam: Don't use u prefix in unicode error messages
Walter Dörwald <walter@livinglogic.de>
parents:
41963
diff
changeset
|
406 "can't translate character '\\U00010000' in position 1: ouch" |
|
30137
df654861ccf6
Enhance message for UnicodeEncodeError and UnicodeTranslateError.
Walter Dörwald <walter@livinglogic.de>
parents:
28917
diff
changeset
|
407 ) |
|
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, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
410 ["g\xfcrk", 1, 3, "ouch"], |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
411 "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
|
412 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
413 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
414 def test_badandgoodstrictexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
415 # "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
|
416 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
417 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
418 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
|
419 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
420 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
421 # "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
|
422 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
423 Exception, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
424 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
|
425 Exception("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
426 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
427 |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
428 # 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
|
429 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
430 UnicodeEncodeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
431 codecs.strict_errors, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
432 UnicodeEncodeError("ascii", "\u3042", 0, 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
|
433 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
434 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
435 def test_badandgoodignoreexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
436 # "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
|
437 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
438 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
439 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
|
440 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
441 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
442 # "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
|
443 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
444 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
445 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
|
446 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
447 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
448 # If the correct exception is passed in, "ignore" returns an empty replacement |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
449 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
450 codecs.ignore_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
451 UnicodeEncodeError("ascii", "\u3042", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
452 ("", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
453 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
454 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
455 codecs.ignore_errors( |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
456 UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
457 ("", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
458 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
459 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
460 codecs.ignore_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
461 UnicodeTranslateError("\u3042", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
462 ("", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
463 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
464 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
465 def test_badandgoodreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
466 # "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
|
467 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
468 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
469 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
|
470 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
471 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
472 # "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
|
473 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
474 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
475 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
|
476 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
477 ) |
|
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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 ) |
|
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 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
|
484 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
|
485 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
|
486 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
|
487 ) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41585
diff
changeset
|
488 # With the correct exception, "replace" returns an "?" or "\ufffd" replacement |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
489 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
490 codecs.replace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
491 UnicodeEncodeError("ascii", "\u3042", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
492 ("?", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
493 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
494 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
495 codecs.replace_errors( |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
496 UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
497 ("\ufffd", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
498 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
499 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
500 codecs.replace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
501 UnicodeTranslateError("\u3042", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
502 ("\ufffd", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
503 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
504 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
505 def test_badandgoodxmlcharrefreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
506 # "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
|
507 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
508 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
509 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
|
510 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
511 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
512 # "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
|
513 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
514 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
515 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
|
516 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
517 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
518 # "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
|
519 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
520 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
521 codecs.xmlcharrefreplace_errors, |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
522 UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 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
|
523 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
524 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
525 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
526 codecs.xmlcharrefreplace_errors, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
527 UnicodeTranslateError("\u3042", 0, 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
|
528 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
529 # 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
|
530 cs = (0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 0x3042) |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
531 s = "".join(chr(c) for c in cs) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
532 self.assertEqual( |
|
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
|
533 codecs.xmlcharrefreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
534 UnicodeEncodeError("ascii", s, 0, len(s), "ouch") |
|
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
|
535 ), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
536 ("".join("&#%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
|
537 ) |
|
25091
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 def test_badandgoodbackslashreplaceexceptions(self): |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
540 # "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
|
541 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
542 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
543 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
|
544 42 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
545 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
546 # "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
|
547 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
548 TypeError, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
549 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
|
550 UnicodeError("ouch") |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
551 ) |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
552 # "backslashreplace" can only be used for encoding |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
553 self.assertRaises( |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
554 TypeError, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
555 codecs.backslashreplace_errors, |
|
43947
cbc8b3bd3157
Rename buffer -> bytearray.
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
556 UnicodeDecodeError("ascii", bytearray(b"\xff"), 0, 1, "ouch") |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
557 ) |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
558 self.assertRaises( |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
559 TypeError, |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
560 codecs.backslashreplace_errors, |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
561 UnicodeTranslateError("\u3042", 0, 1, "ouch") |
|
27310
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
562 ) |
|
a2f84d2835fa
Add comments and remove duplicate tests.
Walter Dörwald <walter@livinglogic.de>
parents:
27183
diff
changeset
|
563 # Use the correct exception |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
564 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
565 codecs.backslashreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
566 UnicodeEncodeError("ascii", "\u3042", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
567 ("\\u3042", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
568 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
569 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
570 codecs.backslashreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
571 UnicodeEncodeError("ascii", "\x00", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
572 ("\\x00", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
573 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
574 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
575 codecs.backslashreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
576 UnicodeEncodeError("ascii", "\xff", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
577 ("\\xff", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
578 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
579 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
580 codecs.backslashreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
581 UnicodeEncodeError("ascii", "\u0100", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
582 ("\\u0100", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
583 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
584 self.assertEqual( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
585 codecs.backslashreplace_errors( |
|
41766
d6aa7edf217a
Add 'U'/'U#' format characters to Py_BuildValue (and thus
Walter Dörwald <walter@livinglogic.de>
parents:
41659
diff
changeset
|
586 UnicodeEncodeError("ascii", "\uffff", 0, 1, "ouch")), |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
587 ("\\uffff", 1) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
588 ) |
|
72683
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
589 if SIZEOF_WCHAR_T > 0: |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
590 self.assertEqual( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
591 codecs.backslashreplace_errors( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
592 UnicodeEncodeError("ascii", "\U00010000", |
|
73353
9191f804d376
Port code page codec to Unicode API.
Martin v. Löwis <martin@v.loewis.de>
parents:
72683
diff
changeset
|
593 0, 1, "ouch")), |
|
9191f804d376
Port code page codec to Unicode API.
Martin v. Löwis <martin@v.loewis.de>
parents:
72683
diff
changeset
|
594 ("\\U00010000", 1) |
|
72683
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
595 ) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
596 self.assertEqual( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
597 codecs.backslashreplace_errors( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
598 UnicodeEncodeError("ascii", "\U0010ffff", |
|
73353
9191f804d376
Port code page codec to Unicode API.
Martin v. Löwis <martin@v.loewis.de>
parents:
72683
diff
changeset
|
599 0, 1, "ouch")), |
|
9191f804d376
Port code page codec to Unicode API.
Martin v. Löwis <martin@v.loewis.de>
parents:
72683
diff
changeset
|
600 ("\\U0010ffff", 1) |
|
72683
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
601 ) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
602 # Lone surrogates (regardless of unicode width) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
603 self.assertEqual( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
604 codecs.backslashreplace_errors( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
605 UnicodeEncodeError("ascii", "\ud800", 0, 1, "ouch")), |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
606 ("\\ud800", 1) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
607 ) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
608 self.assertEqual( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
609 codecs.backslashreplace_errors( |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
610 UnicodeEncodeError("ascii", "\udfff", 0, 1, "ouch")), |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
611 ("\\udfff", 1) |
|
da3bfa2e9daa
Fix text failures when ctypes is not available
Antoine Pitrou <solipsis@pitrou.net>
parents:
72666
diff
changeset
|
612 ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
613 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
614 def test_badhandlerresults(self): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
615 results = ( 42, "foo", (1,2,3), ("foo", 1, 3), ("foo", None), ("foo",), ("foo", 1, 3), ("foo", None), ("foo",) ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
616 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
|
617 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
618 for res in results: |
|
50886
581d8602f3f7
Merged revisions 68746 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47201
diff
changeset
|
619 codecs.register_error("test.badhandler", lambda x: res) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
620 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
|
621 self.assertRaises( |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
622 TypeError, |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
623 "\u3042".encode, |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
624 enc, |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
625 "test.badhandler" |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
626 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
627 for (enc, bytes) in ( |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
628 ("ascii", b"\xff"), |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
629 ("utf-8", b"\xff"), |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
630 ("utf-7", b"+x-"), |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
631 ("unicode-internal", b"\x00"), |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
632 ): |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
633 with test.support.check_warnings(): |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
634 # unicode-internal has been deprecated |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
635 self.assertRaises( |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
636 TypeError, |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
637 bytes.decode, |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
638 enc, |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
639 "test.badhandler" |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
640 ) |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
641 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
642 def test_lookup(self): |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
643 self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
644 self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
645 self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
646 self.assertEqual( |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
647 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
|
648 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
|
649 ) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
650 self.assertEqual( |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
651 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
|
652 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
|
653 ) |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
654 |
|
25139
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
655 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
|
656 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
|
657 if isinstance(exc, UnicodeEncodeError): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
658 return ("\u4242", exc.end) |
|
25139
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
659 else: |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 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
|
664 UnicodeEncodeError, |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
665 "\u4242".encode, |
|
25139
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
666 enc, |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
667 "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
|
668 ) |
|
d446b5151316
Add a test case that checks that the proper exception is raises
Walter Dörwald <walter@livinglogic.de>
parents:
25091
diff
changeset
|
669 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
670 def test_badregistercall(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
671 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
672 # 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
|
673 # 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
|
674 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
|
675 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
|
676 |
|
35882
3236b5fb1fb7
Add tests for various error cases and for readbuffer_encode() and
Walter Dörwald <walter@livinglogic.de>
parents:
35485
diff
changeset
|
677 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
|
678 # 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
|
679 # 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
|
680 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
|
681 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
682 def test_unknownhandler(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
683 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
684 # 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
|
685 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
|
686 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
687 def test_xmlcharrefvalues(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
688 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
689 # 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
|
690 # and inline implementations |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
691 v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000) |
|
72535
7a50e549bd11
Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72475
diff
changeset
|
692 if SIZEOF_WCHAR_T == 4: |
|
27963
226463445697
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
27555
diff
changeset
|
693 v += (100000, 500000, 1000000) |
|
41585
825d966338ea
Rename 'unicode' to 'str' in its tp_name field. Rename 'str' to 'str8'.
Guido van Rossum <guido@python.org>
parents:
41575
diff
changeset
|
694 s = "".join([chr(x) for x in v]) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
695 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
|
696 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
|
697 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
|
698 s.encode(enc, err) |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
699 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
700 def test_decodehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
701 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
702 # 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
|
703 # and callers |
|
42911
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
704 self.assertRaises(LookupError, b"\xff".decode, "ascii", "test.unknown") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
705 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
706 def baddecodereturn1(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
707 return 42 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
708 codecs.register_error("test.baddecodereturn1", baddecodereturn1) |
|
42911
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
709 self.assertRaises(TypeError, b"\xff".decode, "ascii", "test.baddecodereturn1") |
|
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
710 self.assertRaises(TypeError, b"\\".decode, "unicode-escape", "test.baddecodereturn1") |
|
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
711 self.assertRaises(TypeError, b"\\x0".decode, "unicode-escape", "test.baddecodereturn1") |
|
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
712 self.assertRaises(TypeError, b"\\x0y".decode, "unicode-escape", "test.baddecodereturn1") |
|
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
713 self.assertRaises(TypeError, b"\\Uffffeeee".decode, "unicode-escape", "test.baddecodereturn1") |
|
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
714 self.assertRaises(TypeError, b"\\uyyyy".decode, "raw-unicode-escape", "test.baddecodereturn1") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
715 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
716 def baddecodereturn2(exc): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
717 return ("?", None) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
718 codecs.register_error("test.baddecodereturn2", baddecodereturn2) |
|
42911
cb28e14ee808
Changes in anticipation of stricter str vs. bytes enforcement.
Guido van Rossum <guido@python.org>
parents:
42626
diff
changeset
|
719 self.assertRaises(TypeError, b"\xff".decode, "ascii", "test.baddecodereturn2") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
720 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
721 handler = PosReturn() |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
722 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
|
723 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
724 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
725 handler.pos = -1 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
726 self.assertEqual(b"\xff0".decode("ascii", "test.posreturn"), "<?>0") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
727 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
728 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
729 handler.pos = -2 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
730 self.assertEqual(b"\xff0".decode("ascii", "test.posreturn"), "<?><?>") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
731 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
732 # Negative position out of bounds |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
733 handler.pos = -3 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
734 self.assertRaises(IndexError, b"\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
|
735 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
736 # Valid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
737 handler.pos = 1 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
738 self.assertEqual(b"\xff0".decode("ascii", "test.posreturn"), "<?>0") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
739 |
|
34166
e53693a02cf0
Fix copy & paste error in comments.
Walter Dörwald <walter@livinglogic.de>
parents:
31389
diff
changeset
|
740 # 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
|
741 handler.pos = 2 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
742 self.assertEqual(b"\xff0".decode("ascii", "test.posreturn"), "<?>") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
743 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
744 # Invalid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
745 handler.pos = 3 |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
746 self.assertRaises(IndexError, b"\xff0".decode, "ascii", "test.posreturn") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
747 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
748 # Restart at the "0" |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
749 handler.pos = 6 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
750 self.assertEqual(b"\\uyyyy0".decode("raw-unicode-escape", "test.posreturn"), "<?>0") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
751 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
752 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
753 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
754 raise ValueError |
|
41659
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
755 self.assertRaises(UnicodeError, codecs.charmap_decode, b"\xff", "strict", {0xff: None}) |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
756 self.assertRaises(ValueError, codecs.charmap_decode, b"\xff", "strict", D()) |
|
650ff8d7cc38
test_codeccallbacks.py passes again.
Walter Dörwald <walter@livinglogic.de>
parents:
41642
diff
changeset
|
757 self.assertRaises(TypeError, codecs.charmap_decode, b"\xff", "strict", {0xff: sys.maxunicode+1}) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
758 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
759 def test_encodehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
760 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
761 # 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
|
762 # and callers |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
763 self.assertRaises(LookupError, "\xff".encode, "ascii", "test.unknown") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
764 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
765 def badencodereturn1(exc): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
766 return 42 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
767 codecs.register_error("test.badencodereturn1", badencodereturn1) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
768 self.assertRaises(TypeError, "\xff".encode, "ascii", "test.badencodereturn1") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
769 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
770 def badencodereturn2(exc): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
771 return ("?", None) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
772 codecs.register_error("test.badencodereturn2", badencodereturn2) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
773 self.assertRaises(TypeError, "\xff".encode, "ascii", "test.badencodereturn2") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
774 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
775 handler = PosReturn() |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
776 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
|
777 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
778 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
779 handler.pos = -1 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
780 self.assertEqual("\xff0".encode("ascii", "test.posreturn"), b"<?>0") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
781 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
782 # Valid negative position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
783 handler.pos = -2 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
784 self.assertEqual("\xff0".encode("ascii", "test.posreturn"), b"<?><?>") |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
785 |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
786 # Negative position out of bounds |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
787 handler.pos = -3 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
788 self.assertRaises(IndexError, "\xff0".encode, "ascii", "test.posreturn") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
789 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
790 # Valid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
791 handler.pos = 1 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
792 self.assertEqual("\xff0".encode("ascii", "test.posreturn"), b"<?>0") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
793 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
794 # 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
|
795 handler.pos = 2 |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
64590
diff
changeset
|
796 self.assertEqual("\xff0".encode("ascii", "test.posreturn"), b"<?>") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
797 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
798 # Invalid positive position |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
799 handler.pos = 3 |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
800 self.assertRaises(IndexError, "\xff0".encode, "ascii", "test.posreturn") |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
801 |
|
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
802 handler.pos = 0 |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
803 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
804 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
805 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
806 raise ValueError |
|
27555
c267f28724dd
Change the treatment of positions returned by PEP293
Walter Dörwald <walter@livinglogic.de>
parents:
27310
diff
changeset
|
807 for err in ("strict", "replace", "xmlcharrefreplace", "backslashreplace", "test.posreturn"): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
808 self.assertRaises(UnicodeError, codecs.charmap_encode, "\xff", err, {0xff: None}) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
809 self.assertRaises(ValueError, codecs.charmap_encode, "\xff", err, D()) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
810 self.assertRaises(TypeError, codecs.charmap_encode, "\xff", err, {0xff: 300}) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
811 |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
812 def test_translatehelper(self): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
813 # enhance coverage of: |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
814 # 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
|
815 # and callers |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
816 # (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
|
817 # 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
|
818 class D(dict): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
819 def __getitem__(self, key): |
|
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
820 raise ValueError |
|
43673
d66018ed3ded
Remove a test case which is no longer valid.
Georg Brandl <georg@python.org>
parents:
43664
diff
changeset
|
821 #self.assertRaises(ValueError, "\xff".translate, D()) |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
822 self.assertRaises(TypeError, "\xff".translate, {0xff: sys.maxunicode+1}) |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
823 self.assertRaises(TypeError, "\xff".translate, {0xff: ()}) |
|
27177
925a7b1f93ee
Add a few test cases to increase code coverage:
Walter Dörwald <walter@livinglogic.de>
parents:
26405
diff
changeset
|
824 |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
825 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
|
826 charmap = { |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
827 ord("&"): "&", |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
828 ord("<"): "<", |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
829 ord(">"): ">", |
|
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
830 ord('"'): """, |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
831 } |
|
31389
aca1ce1b4b61
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
30765
diff
changeset
|
832 |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
833 for n in (1, 10, 100, 1000): |
|
41575
beacf40b5960
Rip out all the u"..." literals and calls to unicode().
Guido van Rossum <guido@python.org>
parents:
38431
diff
changeset
|
834 text = 'abc<def>ghi'*n |
|
30765
fe3f5592305d
Fix a bug in the memory reallocation code of PyUnicode_TranslateCharmap().
Walter Dörwald <walter@livinglogic.de>
parents:
30138
diff
changeset
|
835 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
|
836 |
|
42408
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
837 def test_mutatingdecodehandler(self): |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
838 baddata = [ |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
839 ("ascii", b"\xff"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
840 ("utf-7", b"++"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
841 ("utf-8", b"\xff"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
842 ("utf-16", b"\xff"), |
|
42626
f1a2d51f1cab
Apply SF patch #1775604: This adds three new codecs (utf-32, utf-32-le and
Walter Dörwald <walter@livinglogic.de>
parents:
42408
diff
changeset
|
843 ("utf-32", b"\xff"), |
|
42408
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
844 ("unicode-escape", b"\\u123g"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
845 ("raw-unicode-escape", b"\\u123g"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
846 ("unicode-internal", b"\xff"), |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
847 ] |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
848 |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
849 def replacing(exc): |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
850 if isinstance(exc, UnicodeDecodeError): |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
851 exc.object = 42 |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
852 return ("\u4242", 0) |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
853 else: |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
854 raise TypeError("don't know how to handle %r" % exc) |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
855 codecs.register_error("test.replacing", replacing) |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
856 |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
857 with test.support.check_warnings(): |
|
73579
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
858 # unicode-internal has been deprecated |
|
ec8c0ac81706
"unicode_internal" codec has been deprecated: fix related tests
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73353
diff
changeset
|
859 for (encoding, data) in baddata: |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
860 with self.assertRaises(TypeError): |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
861 data.decode(encoding, "test.replacing") |
|
42408
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
862 |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
863 def mutating(exc): |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
864 if isinstance(exc, UnicodeDecodeError): |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
865 exc.object[:] = b"" |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
866 return ("\u4242", 0) |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
867 else: |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
868 raise TypeError("don't know how to handle %r" % exc) |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
869 codecs.register_error("test.mutating", mutating) |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
870 # If the decoder doesn't pick up the modified input the following |
|
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
871 # will lead to an endless loop |
|
73600
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
872 with test.support.check_warnings(): |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
873 # unicode-internal has been deprecated |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
874 for (encoding, data) in baddata: |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
875 with self.assertRaises(TypeError): |
|
fe2be7d35660
#13406: fix more deprecation warnings and move the deprecation of unicode-internal earlier in the code.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
73579
diff
changeset
|
876 data.decode(encoding, "test.replacing") |
|
42408
504084c04ac0
Bytes (which are the input for decoding) are mutable now. If a decoding
Walter Dörwald <walter@livinglogic.de>
parents:
42118
diff
changeset
|
877 |
|
25091
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
878 |
|
0337dad8403e
PEP 293 implemention (from SF patch http://www.python.org/sf/432401)
Walter Dörwald <walter@livinglogic.de>
parents:
diff
changeset
|
879 if __name__ == "__main__": |
|
84108
05f7883ee92d
Update various test modules to use unittest.main() for test discovery
Brett Cannon <brett@python.org>
parents:
81805
diff
changeset
|
880 unittest.main() |
