Skip to content

Commit a0a4ab1

Browse files
committed
Add a test case for Weak*Dictionary.update() that would have caught a
recently reported bug; also exposed some other bugs in the implementation.
1 parent 1d9e4b7 commit a0a4ab1

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lib/test/test_weakref.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,31 @@ def test_weak_keys(self):
280280
self.assert_(len(dict) == 0,
281281
"deleting the keys did not clear the dictionary")
282282

283+
def check_update(self, klass, dict):
284+
weakdict = klass()
285+
weakdict.update(dict)
286+
self.assert_(len(weakdict) == len(dict))
287+
for k in weakdict.keys():
288+
self.assert_(dict.has_key(k),
289+
"mysterious new key appeared in weak dict")
290+
v = dict.get(k)
291+
self.assert_(v is weakdict[k])
292+
self.assert_(v is weakdict.get(k))
293+
for k in dict.keys():
294+
self.assert_(weakdict.has_key(k),
295+
"original key disappeared in weak dict")
296+
v = dict[k]
297+
self.assert_(v is weakdict[k])
298+
self.assert_(v is weakdict.get(k))
299+
300+
def test_weak_valued_dict_update(self):
301+
self.check_update(weakref.WeakValueDictionary,
302+
{1: C(), 'a': C(), C(): C()})
303+
304+
def test_weak_keyed_dict_update(self):
305+
self.check_update(weakref.WeakKeyDictionary,
306+
{C(): 1, C(): 2, C(): 3})
307+
283308

284309
run_unittest(ReferencesTestCase)
285310
run_unittest(MappingTestCase)

0 commit comments

Comments
 (0)