SF patch #667730: More DictMixin

* Adds missing pop() methods to weakref.py
* Expands test suite to broaden coverage of objects with
  a mapping interface.

Contributed by Sebastien Keim.
This commit is contained in:
Raymond Hettinger 2003-03-09 07:05:43 +00:00
parent 42182ebaf6
commit 2c2d322884
6 changed files with 222 additions and 4 deletions

View file

@ -517,11 +517,28 @@ class MappingTestCase(TestBase):
self.assert_(len(d) == 1)
self.assert_(d.items() == [('something else', o2)])
from test_userdict import TestMappingProtocol
class WeakValueDictionaryTestCase(TestMappingProtocol):
"""Check that WeakValueDictionary class conforms to the mapping protocol"""
__ref = {"key1":Object(1), "key2":Object(2), "key3":Object(3)}
_tested_class = weakref.WeakValueDictionary
def _reference(self):
return self.__ref.copy()
class WeakKeyDictionaryTestCase(TestMappingProtocol):
"""Check that WeakKeyDictionary class conforms to the mapping protocol"""
__ref = {Object("key1"):1, Object("key2"):2, Object("key3"):3}
_tested_class = weakref.WeakKeyDictionary
def _reference(self):
return self.__ref.copy()
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(ReferencesTestCase))
suite.addTest(unittest.makeSuite(MappingTestCase))
suite.addTest(unittest.makeSuite(WeakValueDictionaryTestCase))
suite.addTest(unittest.makeSuite(WeakKeyDictionaryTestCase))
test_support.run_suite(suite)