diff options
author | Walter Dörwald <walter@livinglogic.de> | 2003-05-18 03:15:10 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2003-05-18 03:15:10 (GMT) |
commit | 9e46abed5061729915ed39d7bb8c4d014369380e (patch) | |
tree | cffba6082397e0470ed2d2e90fd5babf9b654289 /Lib/test | |
parent | df0d87a922ea29f7a410e8b634ae8730caa4438e (diff) | |
download | cpython-9e46abed5061729915ed39d7bb8c4d014369380e.zip cpython-9e46abed5061729915ed39d7bb8c4d014369380e.tar.gz cpython-9e46abed5061729915ed39d7bb8c4d014369380e.tar.bz2 |
Fix array.array.insert(), so that it treats negative indices as
being relative to the end of the array, just like list.insert() does.
This closes SF bug #739313.
Diffstat (limited to 'Lib/test')
-rwxr-xr-x | Lib/test/test_array.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 7a3308b..98589a5 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -82,6 +82,30 @@ class BaseTest(unittest.TestCase): self.assertRaises(TypeError, a.insert, None) self.assertRaises(TypeError, a.insert, 0, None) + a = array.array(self.typecode, self.example) + a.insert(-1, self.example[0]) + self.assertEqual( + a, + array.array( + self.typecode, + self.example[:-1] + self.example[:1] + self.example[-1:] + ) + ) + + a = array.array(self.typecode, self.example) + a.insert(-1000, self.example[0]) + self.assertEqual( + a, + array.array(self.typecode, self.example[:1] + self.example) + ) + + a = array.array(self.typecode, self.example) + a.insert(1000, self.example[0]) + self.assertEqual( + a, + array.array(self.typecode, self.example + self.example[:1]) + ) + def test_tofromfile(self): a = array.array(self.typecode, 2*self.example) self.assertRaises(TypeError, a.tofile) |