mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
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.
This commit is contained in:
parent
df0d87a922
commit
9e46abed50
4 changed files with 34 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue