Fix text failures when ctypes is not available

(followup to Victor's 85d11cf67aa8 and 7a50e549bd11)
This commit is contained in:
Antoine Pitrou 2011-10-05 13:01:41 +02:00
parent 4637309ee6
commit 00b2c86d09
2 changed files with 39 additions and 28 deletions

View file

@ -1,7 +1,12 @@
import test.support, unittest import test.support, unittest
import sys, codecs, html.entities, unicodedata import sys, codecs, html.entities, unicodedata
import ctypes
try:
import ctypes
except ImportError:
ctypes = None
SIZEOF_WCHAR_T = -1
else:
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar) SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
class PosReturn: class PosReturn:
@ -572,10 +577,11 @@ class CodecCallbackTest(unittest.TestCase):
UnicodeEncodeError("ascii", "\uffff", 0, 1, "ouch")), UnicodeEncodeError("ascii", "\uffff", 0, 1, "ouch")),
("\\uffff", 1) ("\\uffff", 1)
) )
if ctypes.sizeof(ctypes.c_wchar) == 2: if SIZEOF_WCHAR_T == 2:
len_wide = 2 len_wide = 2
else: else:
len_wide = 1 len_wide = 1
if SIZEOF_WCHAR_T > 0:
self.assertEqual( self.assertEqual(
codecs.backslashreplace_errors( codecs.backslashreplace_errors(
UnicodeEncodeError("ascii", "\U00010000", UnicodeEncodeError("ascii", "\U00010000",

View file

@ -3,8 +3,13 @@ import unittest
import codecs import codecs
import locale import locale
import sys, _testcapi, io import sys, _testcapi, io
import ctypes
try:
import ctypes
except ImportError:
ctypes = None
SIZEOF_WCHAR_T = -1
else:
SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar) SIZEOF_WCHAR_T = ctypes.sizeof(ctypes.c_wchar)
class Queue(object): class Queue(object):