Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef17f12

Browse files
author
Victor Stinner
committed
Fix test_codeccallbacks for Windows: check size of wchar_t, not sys.maxunicode
1 parent 182d90d commit ef17f12

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/test/test_codeccallbacks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import sys, codecs, html.entities, unicodedata
33
import ctypes
44

5+
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
6+
57
class PosReturn:
68
# this can be used for configurable callbacks
79

@@ -206,7 +208,7 @@ def test_decodeunicodeinternal(self):
206208
b"\x00\x00\x00\x00\x00".decode,
207209
"unicode-internal",
208210
)
209-
if sys.maxunicode > 0xffff:
211+
if SIZEOF_WCHAR_T == 4:
210212
def handler_unicodeinternal(exc):
211213
if not isinstance(exc, UnicodeDecodeError):
212214
raise TypeError("don't know how to handle %r" % exc)
@@ -356,7 +358,7 @@ def test_unicodeencodeerror(self):
356358
["ascii", "\uffffx", 0, 1, "ouch"],
357359
"'ascii' codec can't encode character '\\uffff' in position 0: ouch"
358360
)
359-
if sys.maxunicode > 0xffff:
361+
if SIZEOF_WCHAR_T == 4:
360362
self.check_exceptionobjectargs(
361363
UnicodeEncodeError,
362364
["ascii", "\U00010000x", 0, 1, "ouch"],
@@ -391,7 +393,7 @@ def test_unicodetranslateerror(self):
391393
["g\uffffrk", 1, 2, "ouch"],
392394
"can't translate character '\\uffff' in position 1: ouch"
393395
)
394-
if sys.maxunicode > 0xffff:
396+
if SIZEOF_WCHAR_T == 4:
395397
self.check_exceptionobjectargs(
396398
UnicodeTranslateError,
397399
["g\U00010000rk", 1, 2, "ouch"],
@@ -682,7 +684,7 @@ def test_xmlcharrefvalues(self):
682684
# Python/codecs.c::PyCodec_XMLCharRefReplaceErrors()
683685
# and inline implementations
684686
v = (1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000)
685-
if sys.maxunicode>=100000:
687+
if SIZEOF_WCHAR_T == 4:
686688
v += (100000, 500000, 1000000)
687689
s = "".join([chr(x) for x in v])
688690
codecs.register_error("test.xmlcharrefreplace", codecs.xmlcharrefreplace_errors)

0 commit comments

Comments
 (0)