diff options
author | Eli Bendersky <eliben@gmail.com> | 2011-03-04 10:38:14 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2011-03-04 10:38:14 (GMT) |
commit | 0716a579a427ea3cb0459499644b4288762c6cd4 (patch) | |
tree | 949a6a6b0fa869a71da23390f3d1b6eb9a9ef392 | |
parent | 9479d1ade84d7a386a107989b699fb90b73cfa15 (diff) | |
download | cpython-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
-rw-r--r-- | Doc/library/collections.abc.rst | 2 | ||||
-rw-r--r-- | Lib/test/test_collections.py | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst index 6d1bedb..d341c45 100644 --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -46,7 +46,7 @@ ABC Inherits Abstract Methods Mixin :class:`MutableSequence` :class:`Sequence` ``__setitem__`` Inherited Sequence methods and ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, - and ``insert`` ``remove``, and ``__iadd__`` + and ``insert`` ``remove``, ``clear``, and ``__iadd__`` :class:`Set` :class:`Sized`, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, :class:`Iterable`, ``__gt__``, ``__ge__``, ``__and__``, ``__or__``, 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 |