summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-04-16 17:37:27 (GMT)
committerFred Drake <fdrake@acm.org>2001-04-16 17:37:27 (GMT)
commita0a4ab177297a5d554e9312e6a154103817e8e63 (patch)
treea80742da9903da79039d79129aa8b956e10c1b63 /Lib
parent1d9e4b7de3d15007d5b9e7ac4b38f5e158d3c840 (diff)
downloadcpython-a0a4ab177297a5d554e9312e6a154103817e8e63.zip
cpython-a0a4ab177297a5d554e9312e6a154103817e8e63.tar.gz
cpython-a0a4ab177297a5d554e9312e6a154103817e8e63.tar.bz2
Add a test case for Weak*Dictionary.update() that would have caught a
recently reported bug; also exposed some other bugs in the implementation.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_weakref.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 3fa2400..470c5ca 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -280,6 +280,31 @@ class MappingTestCase(TestBase):
self.assert_(len(dict) == 0,
"deleting the keys did not clear the dictionary")
+ def check_update(self, klass, dict):
+ weakdict = klass()
+ weakdict.update(dict)
+ self.assert_(len(weakdict) == len(dict))
+ for k in weakdict.keys():
+ self.assert_(dict.has_key(k),
+ "mysterious new key appeared in weak dict")
+ v = dict.get(k)
+ self.assert_(v is weakdict[k])
+ self.assert_(v is weakdict.get(k))
+ for k in dict.keys():
+ self.assert_(weakdict.has_key(k),
+ "original key disappeared in weak dict")
+ v = dict[k]
+ self.assert_(v is weakdict[k])
+ self.assert_(v is weakdict.get(k))
+
+ def test_weak_valued_dict_update(self):
+ self.check_update(weakref.WeakValueDictionary,
+ {1: C(), 'a': C(), C(): C()})
+
+ def test_weak_keyed_dict_update(self):
+ self.check_update(weakref.WeakKeyDictionary,
+ {C(): 1, C(): 2, C(): 3})
+
run_unittest(ReferencesTestCase)
run_unittest(MappingTestCase)