[Python-checkins] r88742 - in python/branches/py3k: Doc/library/collections.abc.rst Lib/test/test_collections.py
eli.bendersky
python-checkins at python.org
Fri Mar 4 11:38:14 CET 2011
Author: eli.bendersky
Date: Fri Mar 4 11:38:14 2011
New Revision: 88742
Log:
Mentioned new clear() method of MutableSequence in its doc, and added unit tests for its mixin methods
Modified:
python/branches/py3k/Doc/library/collections.abc.rst
python/branches/py3k/Lib/test/test_collections.py
Modified: python/branches/py3k/Doc/library/collections.abc.rst
==============================================================================
--- python/branches/py3k/Doc/library/collections.abc.rst (original)
+++ python/branches/py3k/Doc/library/collections.abc.rst Fri Mar 4 11:38:14 2011
@@ -46,7 +46,7 @@
: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__``,
Modified: python/branches/py3k/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k/Lib/test/test_collections.py (original)
+++ python/branches/py3k/Lib/test/test_collections.py Fri Mar 4 11:38:14 2011
@@ -728,6 +728,44 @@
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
More information about the Python-checkins
mailing list