Fred Drake avatar Fred Drake committed 6252693

Add a test case for Weak*Dictionary.update() that would have caught a
recently reported bug; also exposed some other bugs in the implementation.

Comments (0)

Files changed (1)

Lib/test/test_weakref.py

         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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.