[Python-checkins] CVS: python/dist/src/Lib/test test_weakref.py,1.7,1.7.2.1
Fred L. Drake
fdrake@users.sourceforge.net
Tue, 12 Mar 2002 21:49:08 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv11141/test
Modified Files:
Tag: release21-maint
test_weakref.py
Log Message:
Add a test that was added in Python 2.2: test Weak*Dictionary.setdefault().
The purpose is to avoid regression on SF bug #529273.
This test is stronger than the one submitted with the bug report.
Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -C2 -d -r1.7 -r1.7.2.1
*** test_weakref.py 16 Apr 2001 17:37:27 -0000 1.7
--- test_weakref.py 13 Mar 2002 05:49:06 -0000 1.7.2.1
***************
*** 281,284 ****
--- 281,309 ----
"deleting the keys did not clear the dictionary")
+ def check_setdefault(self, klass, key, value1, value2):
+ self.assert_(value1 is not value2,
+ "invalid test"
+ " -- value parameters must be distinct objects")
+ weakdict = klass()
+ o = weakdict.setdefault(key, value1)
+ self.assert_(o is value1)
+ self.assert_(weakdict.has_key(key))
+ self.assert_(weakdict.get(key) is value1)
+ self.assert_(weakdict[key] is value1)
+
+ o = weakdict.setdefault(key, value2)
+ self.assert_(o is value1)
+ self.assert_(weakdict.has_key(key))
+ self.assert_(weakdict.get(key) is value1)
+ self.assert_(weakdict[key] is value1)
+
+ def test_weak_valued_dict_setdefault(self):
+ self.check_setdefault(weakref.WeakValueDictionary,
+ "key", C(), C())
+
+ def test_weak_keyed_dict_setdefault(self):
+ self.check_setdefault(weakref.WeakKeyDictionary,
+ C(), "value 1", "value 2")
+
def check_update(self, klass, dict):
weakdict = klass()