diff options
author | Guido van Rossum <guido@python.org> | 2006-05-05 15:15:40 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-05-05 15:15:40 (GMT) |
commit | 2018831b2b2106499a43b37e49e24f7f14154d35 (patch) | |
tree | 1bc981556210e5090784002f7036a2d404856bfe /Lib | |
parent | a0867f79bbdd2b38add23fced8e5ae071ce09f70 (diff) | |
download | cpython-2018831b2b2106499a43b37e49e24f7f14154d35.zip cpython-2018831b2b2106499a43b37e49e24f7f14154d35.tar.gz cpython-2018831b2b2106499a43b37e49e24f7f14154d35.tar.bz2 |
Adding bytes.join() -- a class methods that concatenates an iterable of bytes.
The name and API are questionable, but the functionality isn't.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_bytes.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index 94524d4..051773d 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -347,6 +347,30 @@ class BytesTest(unittest.TestCase): self.failIf(bytes("dab") in b) self.failIf(bytes("abd") in b) + def test_alloc(self): + b = bytes() + alloc = b.__alloc__() + self.assert_(alloc >= 0) + seq = [alloc] + for i in range(100): + b += bytes("x") + alloc = b.__alloc__() + self.assert_(alloc >= len(b)) + if alloc not in seq: + seq.append(alloc) + print seq + + def test_join(self): + self.assertEqual(bytes.join([]), bytes()) + self.assertEqual(bytes.join([bytes()]), bytes()) + for part in [("abc",), ("a", "bc"), ("ab", "c"), ("a", "b", "c")]: + lst = map(bytes, part) + self.assertEqual(bytes.join(lst), bytes("abc")) + self.assertEqual(bytes.join(tuple(lst)), bytes("abc")) + self.assertEqual(bytes.join(iter(lst)), bytes("abc")) + # XXX more... + + # Optimizations: # __iter__? (optimization) # __reversed__? (optimization) |