[Python-checkins] CVS: python/dist/src/Lib/test test_weakref.py,1.6,1.7
Fred L. Drake
fdrake@users.sourceforge.net
Mon, 16 Apr 2001 10:37:29 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv31466
Modified Files:
test_weakref.py
Log Message:
Add a test case for Weak*Dictionary.update() that would have caught a
recently reported bug; also exposed some other bugs in the implementation.
Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** test_weakref.py 2001/04/13 17:18:15 1.6
--- test_weakref.py 2001/04/16 17:37:27 1.7
***************
*** 281,284 ****
--- 281,309 ----
"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)