Kaydet (Commit) 8bf46e4e authored tarafından Michael W. Hudson's avatar Michael W. Hudson

This is patch

[ 555382 ] test_array v.s. --disable-unicode

+ MvL's suggestions.  Just the 32 failing tests in --disable-unicode builds
now...
üst eadb6bb3
...@@ -3,36 +3,38 @@ ...@@ -3,36 +3,38 @@
Roger E. Masse Roger E. Masse
""" """
import array import array
from test_support import verbose, TESTFN, unlink, TestFailed from test_support import verbose, TESTFN, unlink, TestFailed, have_unicode
def main(): def main():
testtype('c', 'c') testtype('c', 'c')
testtype('u', u'\u263a') if have_unicode:
testtype('u', unicode(r'\u263a', 'unicode-escape'))
for type in (['b', 'h', 'i', 'l', 'f', 'd']): for type in (['b', 'h', 'i', 'l', 'f', 'd']):
testtype(type, 1) testtype(type, 1)
testunicode() if have_unicode:
testunicode()
testsubclassing() testsubclassing()
unlink(TESTFN) unlink(TESTFN)
def testunicode(): def testunicode():
try: try:
array.array('b', u'foo') array.array('b', unicode('foo', 'ascii'))
except TypeError: except TypeError:
pass pass
else: else:
raise TestFailed("creating a non-unicode array from " raise TestFailed("creating a non-unicode array from "
"a Unicode string should fail") "a Unicode string should fail")
x = array.array('u', u'\xa0\xc2\u1234') x = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape'))
x.fromunicode(u' ') x.fromunicode(unicode(' ', 'ascii'))
x.fromunicode(u'') x.fromunicode(unicode('', 'ascii'))
x.fromunicode(u'') x.fromunicode(unicode('', 'ascii'))
x.fromunicode(u'\x11abc\xff\u1234') x.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape'))
s = x.tounicode() s = x.tounicode()
if s != u'\xa0\xc2\u1234 \x11abc\xff\u1234': if s != unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape'):
raise TestFailed("fromunicode()/tounicode()") raise TestFailed("fromunicode()/tounicode()")
s = u'\x00="\'a\\b\x80\xff\u0000\u0001\u1234' s = unicode(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape')
a = array.array('u', s) a = array.array('u', s)
if verbose: if verbose:
print "repr of type 'u' array:", repr(a) print "repr of type 'u' array:", repr(a)
...@@ -235,42 +237,42 @@ def testtype(type, example): ...@@ -235,42 +237,42 @@ def testtype(type, example):
if a != array.array(type, "dca"): if a != array.array(type, "dca"):
raise TestFailed, "array(%s) reverse-test" % `type` raise TestFailed, "array(%s) reverse-test" % `type`
elif type == 'u': elif type == 'u':
a = array.array(type, u"abcde") a = array.array(type, unicode("abcde", 'ascii'))
a[:-1] = a a[:-1] = a
if a != array.array(type, u"abcdee"): if a != array.array(type, unicode("abcdee", 'ascii')):
raise TestFailed, "array(%s) self-slice-assign (head)" % `type` raise TestFailed, "array(%s) self-slice-assign (head)" % `type`
a = array.array(type, u"abcde") a = array.array(type, unicode("abcde", 'ascii'))
a[1:] = a a[1:] = a
if a != array.array(type, u"aabcde"): if a != array.array(type, unicode("aabcde", 'ascii')):
raise TestFailed, "array(%s) self-slice-assign (tail)" % `type` raise TestFailed, "array(%s) self-slice-assign (tail)" % `type`
a = array.array(type, u"abcde") a = array.array(type, unicode("abcde", 'ascii'))
a[1:-1] = a a[1:-1] = a
if a != array.array(type, u"aabcdee"): if a != array.array(type, unicode("aabcdee", 'ascii')):
raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type` raise TestFailed, "array(%s) self-slice-assign (cntr)" % `type`
if a.index(u"e") != 5: if a.index(unicode("e", 'ascii')) != 5:
raise TestFailed, "array(%s) index-test" % `type` raise TestFailed, "array(%s) index-test" % `type`
if a.count(u"a") != 2: if a.count(unicode("a", 'ascii')) != 2:
raise TestFailed, "array(%s) count-test" % `type` raise TestFailed, "array(%s) count-test" % `type`
a.remove(u"e") a.remove(unicode("e", 'ascii'))
if a != array.array(type, u"aabcde"): if a != array.array(type, unicode("aabcde", 'ascii')):
raise TestFailed, "array(%s) remove-test" % `type` raise TestFailed, "array(%s) remove-test" % `type`
if a.pop(0) != u"a": if a.pop(0) != unicode("a", 'ascii'):
raise TestFailed, "array(%s) pop-test" % `type` raise TestFailed, "array(%s) pop-test" % `type`
if a.pop(1) != u"b": if a.pop(1) != unicode("b", 'ascii'):
raise TestFailed, "array(%s) pop-test" % `type` raise TestFailed, "array(%s) pop-test" % `type`
a.extend(array.array(type, u"xyz")) a.extend(array.array(type, unicode("xyz", 'ascii')))
if a != array.array(type, u"acdexyz"): if a != array.array(type, unicode("acdexyz", 'ascii')):
raise TestFailed, "array(%s) extend-test" % `type` raise TestFailed, "array(%s) extend-test" % `type`
a.pop() a.pop()
a.pop() a.pop()
a.pop() a.pop()
x = a.pop() x = a.pop()
if x != u'e': if x != unicode('e', 'ascii'):
raise TestFailed, "array(%s) pop-test" % `type` raise TestFailed, "array(%s) pop-test" % `type`
if a != array.array(type, u"acd"): if a != array.array(type, unicode("acd", 'ascii')):
raise TestFailed, "array(%s) pop-test" % `type` raise TestFailed, "array(%s) pop-test" % `type`
a.reverse() a.reverse()
if a != array.array(type, u"dca"): if a != array.array(type, unicode("dca", 'ascii')):
raise TestFailed, "array(%s) reverse-test" % `type` raise TestFailed, "array(%s) reverse-test" % `type`
else: else:
a = array.array(type, [1, 2, 3, 4, 5]) a = array.array(type, [1, 2, 3, 4, 5])
......
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