Issue #1283: Allow any iterable of integers to be passed to

bytearray.extend().
This commit is contained in:
Alexandre Vassalotti 2007-12-04 05:51:13 +00:00
parent b00324f9b4
commit 09121e8eb2
2 changed files with 89 additions and 18 deletions

View file

@ -529,6 +529,24 @@ class BytesTest(unittest.TestCase):
a.extend(a)
self.assertEqual(a, orig + orig)
self.assertEqual(a[5:], orig)
a = bytearray(b'')
# Test iterators that don't have a __length_hint__
a.extend(map(int, orig * 25))
a.extend(int(x) for x in orig * 25)
self.assertEqual(a, orig * 50)
self.assertEqual(a[-5:], orig)
a = bytearray(b'')
a.extend(iter(map(int, orig * 50)))
self.assertEqual(a, orig * 50)
self.assertEqual(a[-5:], orig)
a = bytearray(b'')
a.extend(list(map(int, orig * 50)))
self.assertEqual(a, orig * 50)
self.assertEqual(a[-5:], orig)
a = bytearray(b'')
self.assertRaises(ValueError, a.extend, [0, 1, 2, 256])
self.assertRaises(ValueError, a.extend, [0, 1, 2, -1])
self.assertEqual(len(a), 0)
def test_remove(self):
b = bytearray(b'hello')