summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-09-27 18:01:22 (GMT)
committerGuido van Rossum <guido@python.org>2007-09-27 18:01:22 (GMT)
commitf1044293fa36667b5ba11fbc7acac21a03b82710 (patch)
tree41aac1b32323f1ae889d88c097157d330dc1aff7 /Lib/test/string_tests.py
parent4e02c503e789337b07cc14ece3f5adbf23732c89 (diff)
downloadcpython-f1044293fa36667b5ba11fbc7acac21a03b82710.zip
cpython-f1044293fa36667b5ba11fbc7acac21a03b82710.tar.gz
cpython-f1044293fa36667b5ba11fbc7acac21a03b82710.tar.bz2
Patch # 1145 by Thomas Lee:
str.join(...) now applies str() to the sequence elements if they're not strings alraedy, except for bytes, which still raise TypeError (for the same reasons why ""==b"" raises it).
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 9e178ca..cb8900d 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -13,6 +13,7 @@ class Sequence:
class BadSeq1(Sequence):
def __init__(self): self.seq = [7, 'hello', 123]
+ def __str__(self): return '{0} {1} {2}'.format(*self.seq)
class BadSeq2(Sequence):
def __init__(self): self.seq = ['a', 'b', 'c']
@@ -987,19 +988,19 @@ class MixinStrUnicodeUserStringTest:
self.checkequal('abc', 'a', 'join', ('abc',))
self.checkequal('z', 'a', 'join', UserList(['z']))
self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
- self.checkraises(TypeError, '.', 'join', ['a', 'b', 3])
+ self.checkequal('a.b.3', '.', 'join', ['a', 'b', 3])
for i in [5, 25, 125]:
self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
['a' * i] * i)
self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
('a' * i,) * i)
- self.checkraises(TypeError, ' ', 'join', BadSeq1())
+ self.checkequal(str(BadSeq1()), ' ', 'join', BadSeq1())
self.checkequal('a b c', ' ', 'join', BadSeq2())
self.checkraises(TypeError, ' ', 'join')
self.checkraises(TypeError, ' ', 'join', 7)
- self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123]))
+ self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
try:
def f():
yield 4 + ""