gh-114894: add array.array.clear() method (#114919)

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
Mike Zimin 2024-02-10 19:59:46 +04:00 committed by GitHub
parent 5319c66550
commit 9d1a353230
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 71 additions and 1 deletions

View file

@ -1014,6 +1014,29 @@ class BaseTest:
array.array(self.typecode, self.example[3:]+self.example[:-1])
)
def test_clear(self):
a = array.array(self.typecode, self.example)
with self.assertRaises(TypeError):
a.clear(42)
a.clear()
self.assertEqual(len(a), 0)
self.assertEqual(a.typecode, self.typecode)
a = array.array(self.typecode)
a.clear()
self.assertEqual(len(a), 0)
self.assertEqual(a.typecode, self.typecode)
a = array.array(self.typecode, self.example)
a.clear()
a.append(self.example[2])
a.append(self.example[3])
self.assertEqual(a, array.array(self.typecode, self.example[2:4]))
with memoryview(a):
with self.assertRaises(BufferError):
a.clear()
def test_reverse(self):
a = array.array(self.typecode, self.example)
self.assertRaises(TypeError, a.reverse, 42)