diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-02-26 21:52:25 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-02-26 21:52:25 (GMT) |
commit | 742c5961dd09e4e674feef10c2bd43191cdf828e (patch) | |
tree | 7980944228edef448afe65fd4d6530d859e6f8fb /Lib | |
parent | e55aa69efc048ef4a9eb7525ad2fd74fd3dfbf05 (diff) | |
parent | c472c5d7bd2e2b347af650cf448bad71e33aa317 (diff) | |
download | cpython-742c5961dd09e4e674feef10c2bd43191cdf828e.zip cpython-742c5961dd09e4e674feef10c2bd43191cdf828e.tar.gz cpython-742c5961dd09e4e674feef10c2bd43191cdf828e.tar.bz2 |
(Merge 3.3) Issue #17223: Fix test_array on Windows (16-bit wchar_t/Py_UNICODE)
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/test/test_array.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index b024276..163dace 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -24,6 +24,17 @@ try: except struct.error: have_long_long = False +try: + import ctypes + sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) +except ImportError: + import sys + if sys.platform == 'win32': + sizeof_wchar = 2 + else: + sizeof_wchar = 4 + + class ArraySubclass(array.array): pass @@ -1040,16 +1051,6 @@ class UnicodeTest(StringTest, unittest.TestCase): minitemsize = 2 def test_unicode(self): - try: - import ctypes - sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) - except ImportError: - import sys - if sys.platform == 'win32': - sizeof_wchar = 2 - else: - sizeof_wchar = 4 - self.assertRaises(TypeError, array.array, 'b', 'foo') a = array.array('u', '\xa0\xc2\u1234') @@ -1071,7 +1072,13 @@ class UnicodeTest(StringTest, unittest.TestCase): def test_issue17223(self): # this used to crash - a = array.array('u', b'\xff' * 4) + if sizeof_wchar == 4: + # U+FFFFFFFF is an invalid code point in Unicode 6.0 + invalid_str = b'\xff\xff\xff\xff' + else: + # invalid UTF-16 surrogate pair + invalid_str = b'\xff\xdf\x61\x00' + a = array.array('u', invalid_str) self.assertRaises(ValueError, a.tounicode) self.assertRaises(ValueError, str, a) |