MCPcopy Index your code
hub / github.com/python/cpython / test_join

Method test_join

Lib/test/string_tests.py:1355–1392  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1353 #self.checkraises(OverflowError, 10000*'abc', '__mul__', 2000000000)
1354
1355 def test_join(self):
1356 # join now works with any sequence type
1357 # moved here, because the argument order is
1358 # different in string.join
1359 self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
1360 self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd'))
1361 self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
1362 self.checkequal('ac', '', 'join', ('a', '', 'c', ''))
1363 self.checkequal('w x y z', ' ', 'join', Sequence())
1364 self.checkequal('abc', 'a', 'join', ('abc',))
1365 self.checkequal('z', 'a', 'join', UserList(['z']))
1366 self.checkequal('a.b.c', '.', 'join', ['a', 'b', 'c'])
1367 self.assertRaises(TypeError, '.'.join, ['a', 'b', 3])
1368 for i in [5, 25, 125]:
1369 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
1370 ['a' * i] * i)
1371 self.checkequal(((('a' * i) + '-') * i)[:-1], '-', 'join',
1372 ('a' * i,) * i)
1373
1374 class LiesAboutLengthSeq(Sequence):
1375 def __init__(self): self.seq = ['a', 'b', 'c']
1376 def __len__(self): return 8
1377
1378 self.checkequal('a b c', ' ', 'join', LiesAboutLengthSeq())
1379
1380 self.checkraises(TypeError, ' ', 'join')
1381 self.checkraises(TypeError, ' ', 'join', None)
1382 self.checkraises(TypeError, ' ', 'join', 7)
1383 self.checkraises(TypeError, ' ', 'join', [1, 2, bytes()])
1384 try:
1385 def f():
1386 yield 4 + ""
1387 self.fixtype(' ').join(f())
1388 except TypeError as e:
1389 if '+' not in str(e):
1390 self.fail('join() ate exception message')
1391 else:
1392 self.fail('exception not raised')
1393
1394 def test_formatting(self):
1395 self.checkequal('+hello+', '+%s+', '__mod__', 'hello')

Callers

nothing calls this directly

Calls 11

UserListClass · 0.90
LiesAboutLengthSeqClass · 0.85
strFunction · 0.85
SequenceClass · 0.70
fFunction · 0.70
checkequalMethod · 0.45
assertRaisesMethod · 0.45
checkraisesMethod · 0.45
joinMethod · 0.45
fixtypeMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected