mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Slight improvement to Unicode test suite, inspired by patch #102563:
also test join method of 8-bit strings. Also changed the test() function to (1) compare the types of the expected and actual result, and (2) in verbose mode, print the repr() of the output.
This commit is contained in:
parent
b5ec5e4b41
commit
15ffc71c0f
1 changed files with 11 additions and 9 deletions
|
|
@ -10,7 +10,7 @@ import sys
|
||||||
|
|
||||||
def test(method, input, output, *args):
|
def test(method, input, output, *args):
|
||||||
if verbose:
|
if verbose:
|
||||||
print '%s.%s%s =? %s... ' % (repr(input), method, args, output),
|
print '%s.%s%s =? %s... ' % (repr(input), method, args, repr(output)),
|
||||||
try:
|
try:
|
||||||
f = getattr(input, method)
|
f = getattr(input, method)
|
||||||
value = apply(f, args)
|
value = apply(f, args)
|
||||||
|
|
@ -19,7 +19,7 @@ def test(method, input, output, *args):
|
||||||
exc = sys.exc_info()[:2]
|
exc = sys.exc_info()[:2]
|
||||||
else:
|
else:
|
||||||
exc = None
|
exc = None
|
||||||
if value != output:
|
if value != output or type(value) is not type(output):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'no'
|
print 'no'
|
||||||
print '*',f, `input`, `output`, `value`
|
print '*',f, `input`, `output`, `value`
|
||||||
|
|
@ -70,19 +70,21 @@ test('split', u'a b c d ', [u'a', u'b', u'c', u'd'])
|
||||||
|
|
||||||
# join now works with any sequence type
|
# join now works with any sequence type
|
||||||
class Sequence:
|
class Sequence:
|
||||||
def __init__(self): self.seq = 'wxyz'
|
def __init__(self, seq): self.seq = seq
|
||||||
def __len__(self): return len(self.seq)
|
def __len__(self): return len(self.seq)
|
||||||
def __getitem__(self, i): return self.seq[i]
|
def __getitem__(self, i): return self.seq[i]
|
||||||
|
|
||||||
test('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd'])
|
test('join', u' ', u'a b c d', [u'a', u'b', u'c', u'd'])
|
||||||
|
test('join', u' ', u'a b c d', ['a', 'b', u'c', u'd'])
|
||||||
test('join', u'', u'abcd', (u'a', u'b', u'c', u'd'))
|
test('join', u'', u'abcd', (u'a', u'b', u'c', u'd'))
|
||||||
test('join', u' ', u'w x y z', Sequence())
|
test('join', u' ', u'w x y z', Sequence('wxyz'))
|
||||||
test('join', u' ', TypeError, 7)
|
test('join', u' ', TypeError, 7)
|
||||||
|
test('join', u' ', TypeError, Sequence([7, u'hello', 123L]))
|
||||||
class BadSeq(Sequence):
|
test('join', ' ', u'a b c d', [u'a', u'b', u'c', u'd'])
|
||||||
def __init__(self): self.seq = [7, u'hello', 123L]
|
test('join', ' ', u'a b c d', ['a', 'b', u'c', u'd'])
|
||||||
|
test('join', '', u'abcd', (u'a', u'b', u'c', u'd'))
|
||||||
test('join', u' ', TypeError, BadSeq())
|
test('join', ' ', u'w x y z', Sequence(u'wxyz'))
|
||||||
|
test('join', ' ', TypeError, 7)
|
||||||
|
|
||||||
result = u''
|
result = u''
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue