aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_array.py
diff options
context:
space:
mode:
authorMike Zimin <122507876+mikeziminio@users.noreply.github.com>2024-02-10 19:59:46 +0400
committerGitHub <noreply@github.com>2024-02-10 07:59:46 -0800
commit9d1a353230f555fc28239c5ca1e82b758084e02a (patch)
tree55d1b4e09e8661e085c935b61fecdf84ade80ba7 /Lib/test/test_array.py
parent5319c66550a6d6c6698dea75c0a0ee005873ce61 (diff)
downloadcpython-9d1a353230f555fc28239c5ca1e82b758084e02a.tar.gz
cpython-9d1a353230f555fc28239c5ca1e82b758084e02a.zip
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>
Diffstat (limited to 'Lib/test/test_array.py')
-rwxr-xr-xLib/test/test_array.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index a219fa365e7..95383be9659 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -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)