Issue #1283: Allow any iterable of integers to be passed to
bytearray.extend().
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 659afac..f037d4c 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -529,6 +529,24 @@
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')