summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2011-03-04 10:38:14 (GMT)
committerEli Bendersky <eliben@gmail.com>2011-03-04 10:38:14 (GMT)
commit0716a579a427ea3cb0459499644b4288762c6cd4 (patch)
tree949a6a6b0fa869a71da23390f3d1b6eb9a9ef392 /Lib/test/test_collections.py
parent9479d1ade84d7a386a107989b699fb90b73cfa15 (diff)
downloadcpython-0716a579a427ea3cb0459499644b4288762c6cd4.zip
cpython-0716a579a427ea3cb0459499644b4288762c6cd4.tar.gz
cpython-0716a579a427ea3cb0459499644b4288762c6cd4.tar.bz2
Mentioned new clear() method of MutableSequence in its doc, and added unit tests for its mixin methods
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index bb11500..d71fb01 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -728,6 +728,44 @@ class TestCollectionABCs(ABCTestCase):
self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
'__len__', '__getitem__', '__setitem__', '__delitem__', 'insert')
+ def test_MutableSequence_mixins(self):
+ # Test the mixins of MutableSequence by creating a miminal concrete
+ # class inherited from it.
+ class MutableSequenceSubclass(MutableSequence):
+ def __init__(self):
+ self.lst = []
+
+ def __setitem__(self, index, value):
+ self.lst[index] = value
+
+ def __getitem__(self, index):
+ return self.lst[index]
+
+ def __len__(self):
+ return len(self.lst)
+
+ def __delitem__(self, index):
+ del self.lst[index]
+
+ def insert(self, index, value):
+ self.lst.insert(index, value)
+
+ mss = MutableSequenceSubclass()
+ mss.append(0)
+ mss.extend((1, 2, 3, 4))
+ self.assertEqual(len(mss), 5)
+ self.assertEqual(mss[3], 3)
+ mss.reverse()
+ self.assertEqual(mss[3], 1)
+ mss.pop()
+ self.assertEqual(len(mss), 4)
+ mss.remove(3)
+ self.assertEqual(len(mss), 3)
+ mss += (10, 20, 30)
+ self.assertEqual(len(mss), 6)
+ self.assertEqual(mss[-1], 30)
+ mss.clear()
+ self.assertEqual(len(mss), 0)
################################################################################
### Counter