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

Skip to content

Commit 8bf46e4

Browse files
author
Michael W. Hudson
committed
This is patch
[ 555382 ] test_array v.s. --disable-unicode + MvL's suggestions. Just the 32 failing tests in --disable-unicode builds now...
1 parent eadb6bb commit 8bf46e4

1 file changed

Lines changed: 30 additions & 28 deletions

File tree

Lib/test/test_array.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,38 @@
33
Roger E. Masse
44
"""
55
import array
6-
from test_support import verbose, TESTFN, unlink, TestFailed
6+
from test_support import verbose, TESTFN, unlink, TestFailed, have_unicode
77

88
def main():
99
testtype('c', 'c')
10-
testtype('u', u'\u263a')
10+
if have_unicode:
11+
testtype('u', unicode(r'\u263a', 'unicode-escape'))
1112
for type in (['b', 'h', 'i', 'l', 'f', 'd']):
1213
testtype(type, 1)
13-
testunicode()
14+
if have_unicode:
15+
testunicode()
1416
testsubclassing()
1517
unlink(TESTFN)
1618

1719
def testunicode():
1820
try:
19-
array.array('b', u'foo')
21+
array.array('b', unicode('foo', 'ascii'))
2022
except TypeError:
2123
pass
2224
else:
2325
raise TestFailed("creating a non-unicode array from "
2426
"a Unicode string should fail")
2527

26-
x = array.array('u', u'\xa0\xc2\u1234')
27-
x.fromunicode(u' ')
28-
x.fromunicode(u'')
29-
x.fromunicode(u'')
30-
x.fromunicode(u'\x11abc\xff\u1234')
28+
x = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape'))
29+
x.fromunicode(unicode(' ', 'ascii'))
30+
x.fromunicode(unicode('', 'ascii'))
31+
x.fromunicode(unicode('', 'ascii'))
32+
x.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape'))
3133
s = x.tounicode()
32-
if s != u'\xa0\xc2\u1234 \x11abc\xff\u1234':
34+
if s != unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape'):
3335
raise TestFailed("fromunicode()/tounicode()")
3436

35-
s = u'\x00="\'a\\b\x80\xff\u0000\u0001\u1234'
37+
s = unicode(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape')
3638
a = array.array('u', s)
3739
if verbose:
3840
print "repr of type 'u' array:", repr(a)
@@ -235,42 +237,42 @@ def testtype(type, example):
235237
if a != array.array(type, "dca"):
236238
raise TestFailed, "array(%s) reverse-test" % `type`
237239
elif type == 'u':
238-
a = array.array(type, u"abcde")
240+
a = array.array(type, unicode("abcde", 'ascii'))
239241
a[:-1] = a
240-
if a != array.array(type, u"abcdee"):
242+
if a != array.array(type, unicode("abcdee", 'ascii')):
241243
raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
242-
a = array.array(type, u"abcde")
244+
a = array.array(type, unicode("abcde", 'ascii'))
243245
a[1:] = a
244-
if a != array.array(type, u"aabcde"):
246+
if a != array.array(type, unicode("aabcde", 'ascii')):
245247
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
246-
a = array.array(type, u"abcde")
248+
a = array.array(type, unicode("abcde", 'ascii'))
247249
a[1:-1] = a
248-
if a != array.array(type, u"aabcdee"):
250+
if a != array.array(type, unicode("aabcdee", 'ascii')):
249251
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
250-
if a.index(u"e") != 5:
252+
if a.index(unicode("e", 'ascii')) != 5:
251253
raise TestFailed, "array(%s) index-test" % `type`
252-
if a.count(u"a") != 2:
254+
if a.count(unicode("a", 'ascii')) != 2:
253255
raise TestFailed, "array(%s) count-test" % `type`
254-
a.remove(u"e")
255-
if a != array.array(type, u"aabcde"):
256+
a.remove(unicode("e", 'ascii'))
257+
if a != array.array(type, unicode("aabcde", 'ascii')):
256258
raise TestFailed, "array(%s) remove-test" % `type`
257-
if a.pop(0) != u"a":
259+
if a.pop(0) != unicode("a", 'ascii'):
258260
raise TestFailed, "array(%s) pop-test" % `type`
259-
if a.pop(1) != u"b":
261+
if a.pop(1) != unicode("b", 'ascii'):
260262
raise TestFailed, "array(%s) pop-test" % `type`
261-
a.extend(array.array(type, u"xyz"))
262-
if a != array.array(type, u"acdexyz"):
263+
a.extend(array.array(type, unicode("xyz", 'ascii')))
264+
if a != array.array(type, unicode("acdexyz", 'ascii')):
263265
raise TestFailed, "array(%s) extend-test" % `type`
264266
a.pop()
265267
a.pop()
266268
a.pop()
267269
x = a.pop()
268-
if x != u'e':
270+
if x != unicode('e', 'ascii'):
269271
raise TestFailed, "array(%s) pop-test" % `type`
270-
if a != array.array(type, u"acd"):
272+
if a != array.array(type, unicode("acd", 'ascii')):
271273
raise TestFailed, "array(%s) pop-test" % `type`
272274
a.reverse()
273-
if a != array.array(type, u"dca"):
275+
if a != array.array(type, unicode("dca", 'ascii')):
274276
raise TestFailed, "array(%s) reverse-test" % `type`
275277
else:
276278
a = array.array(type, [1, 2, 3, 4, 5])

0 commit comments

Comments
 (0)