Kaydet (Commit) ef17f12a authored tarafından Victor Stinner's avatar Victor Stinner

Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode

üst 182d90d9
...@@ -2,6 +2,8 @@ import test.support, unittest ...@@ -2,6 +2,8 @@ import test.support, unittest
import sys, codecs, html.entities, unicodedata import sys, codecs, html.entities, unicodedata
import ctypes import ctypes
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
class PosReturn: class PosReturn:
# this can be used for configurable callbacks # this can be used for configurable callbacks
...@@ -206,7 +208,7 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -206,7 +208,7 @@ class CodecCallbackTest(unittest.TestCase):
b"\x00\x00\x00\x00\x00".decode, b"\x00\x00\x00\x00\x00".decode,
"unicode-internal", "unicode-internal",
) )
if sys.maxunicode > 0xffff: if SIZEOF_WCHAR_T == 4:
def handler_unicodeinternal(exc): def handler_unicodeinternal(exc):
if not isinstance(exc, UnicodeDecodeError): if not isinstance(exc, UnicodeDecodeError):
raise TypeError("don't know how to handle %r" % exc) raise TypeError("don't know how to handle %r" % exc)
...@@ -356,7 +358,7 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -356,7 +358,7 @@ class CodecCallbackTest(unittest.TestCase):
["ascii", "\uffffx", 0, 1, "ouch"], ["ascii", "\uffffx", 0, 1, "ouch"],
"'ascii' codec can't encode character '\\uffff' in position 0: ouch" "'ascii' codec can't encode character '\\uffff' in position 0: ouch"
) )
if sys.maxunicode > 0xffff: if SIZEOF_WCHAR_T == 4:
self.check_exceptionobjectargs( self.check_exceptionobjectargs(
UnicodeEncodeError, UnicodeEncodeError,
["ascii", "\U00010000x", 0, 1, "ouch"], ["ascii", "\U00010000x", 0, 1, "ouch"],
...@@ -391,7 +393,7 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -391,7 +393,7 @@ class CodecCallbackTest(unittest.TestCase):
["g\uffffrk", 1, 2, "ouch"], ["g\uffffrk", 1, 2, "ouch"],
"can't translate character '\\uffff' in position 1: ouch" "can't translate character '\\uffff' in position 1: ouch"
) )
if sys.maxunicode > 0xffff: if SIZEOF_WCHAR_T == 4:
self.check_exceptionobjectargs( self.check_exceptionobjectargs(
UnicodeTranslateError, UnicodeTranslateError,
["g\U00010000rk", 1, 2, "ouch"], ["g\U00010000rk", 1, 2, "ouch"],
...@@ -682,7 +684,7 @@ class CodecCallbackTest(unittest.TestCase): ...@@ -682,7 +684,7 @@ class CodecCallbackTest(unittest.TestCase):
# Python/codecs.c::PyCodec_XMLCharRefReplaceErrors() # Python/codecs.c::PyCodec_XMLCharRefReplaceErrors()
# and inline implementations # and inline implementations
v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000) v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000)
if sys.maxunicode>=100000: if SIZEOF_WCHAR_T == 4:
v += (100000, 500000, 1000000) v += (100000, 500000, 1000000)
s = "".join([chr(x) for x in v]) s = "".join([chr(x) for x in v])
codecs.register_error("test.xmlcharrefreplace", codecs.xmlcharrefreplace_errors) codecs.register_error("test.xmlcharrefreplace", codecs.xmlcharrefreplace_errors)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment