aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_array.py
diff options
context:
space:
mode:
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)