summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_weakref.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2006-05-02 06:53:59 (GMT)
committerFred Drake <fdrake@acm.org>2006-05-02 06:53:59 (GMT)
commit017e68c413be6262eb1e71b0f0c5676d6db33a43 (patch)
treed9d2649217fc7fc9a2eb2f98870f434a1f1d37ae /Lib/test/test_weakref.py
parenta6d01cec3ff3b945565653f96141c693af639924 (diff)
downloadcpython-017e68c413be6262eb1e71b0f0c5676d6db33a43.zip
cpython-017e68c413be6262eb1e71b0f0c5676d6db33a43.tar.gz
cpython-017e68c413be6262eb1e71b0f0c5676d6db33a43.tar.bz2
SF #1479988: add methods to allow access to weakrefs for the
weakref.WeakKeyDictionary and weakref.WeakValueDictionary
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r--Lib/test/test_weakref.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 9634ef2..392e5fa 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -769,10 +769,54 @@ class MappingTestCase(TestBase):
dict, objects = self.make_weak_keyed_dict()
self.check_iters(dict)
+ # Test keyrefs()
+ refs = dict.keyrefs()
+ self.assertEqual(len(refs), len(objects))
+ objects2 = list(objects)
+ for wr in refs:
+ ob = wr()
+ self.assert_(dict.has_key(ob))
+ self.assert_(ob in dict)
+ self.assertEqual(ob.arg, dict[ob])
+ objects2.remove(ob)
+ self.assertEqual(len(objects2), 0)
+
+ # Test iterkeyrefs()
+ objects2 = list(objects)
+ self.assertEqual(len(list(dict.iterkeyrefs())), len(objects))
+ for wr in dict.iterkeyrefs():
+ ob = wr()
+ self.assert_(dict.has_key(ob))
+ self.assert_(ob in dict)
+ self.assertEqual(ob.arg, dict[ob])
+ objects2.remove(ob)
+ self.assertEqual(len(objects2), 0)
+
def test_weak_valued_iters(self):
dict, objects = self.make_weak_valued_dict()
self.check_iters(dict)
+ # Test valuerefs()
+ refs = dict.valuerefs()
+ self.assertEqual(len(refs), len(objects))
+ objects2 = list(objects)
+ for wr in refs:
+ ob = wr()
+ self.assertEqual(ob, dict[ob.arg])
+ self.assertEqual(ob.arg, dict[ob.arg].arg)
+ objects2.remove(ob)
+ self.assertEqual(len(objects2), 0)
+
+ # Test itervaluerefs()
+ objects2 = list(objects)
+ self.assertEqual(len(list(dict.itervaluerefs())), len(objects))
+ for wr in dict.itervaluerefs():
+ ob = wr()
+ self.assertEqual(ob, dict[ob.arg])
+ self.assertEqual(ob.arg, dict[ob.arg].arg)
+ objects2.remove(ob)
+ self.assertEqual(len(objects2), 0)
+
def check_iters(self, dict):
# item iterator:
items = dict.items()