MCPcopy Index your code
hub / github.com/python/cpython / test_weak_keys

Method test_weak_keys

Lib/test/test_weakref.py:1413–1441  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1411 self.assertRaises(KeyError, dict.__getitem__, 2)
1412
1413 def test_weak_keys(self):
1414 #
1415 # This exercises d.copy(), d.items(), d[] = v, d[], del d[],
1416 # len(d), k in d.
1417 #
1418 dict, objects = self.make_weak_keyed_dict()
1419 for o in objects:
1420 self.assertEqual(weakref.getweakrefcount(o), 1,
1421 "wrong number of weak references to %r!" % o)
1422 self.assertIs(o.arg, dict[o],
1423 "wrong object returned by weak dict!")
1424 items1 = dict.items()
1425 items2 = dict.copy().items()
1426 self.assertEqual(set(items1), set(items2),
1427 "cloning of weak-keyed dictionary did not work!")
1428 del items1, items2
1429 self.assertEqual(len(dict), self.COUNT)
1430 del objects[0]
1431 gc_collect() # For PyPy or other GCs.
1432 self.assertEqual(len(dict), (self.COUNT - 1),
1433 "deleting object did not cause dictionary update")
1434 del objects, o
1435 gc_collect() # For PyPy or other GCs.
1436 self.assertEqual(len(dict), 0,
1437 "deleting the keys did not clear the dictionary")
1438 o = Object(42)
1439 dict[o] = "What is the meaning of the universe?"
1440 self.assertIn(o, dict)
1441 self.assertNotIn(34, dict)
1442
1443 def test_weak_keyed_iters(self):
1444 dict, objects = self.make_weak_keyed_dict()

Callers

nothing calls this directly

Calls 10

make_weak_keyed_dictMethod · 0.95
gc_collectFunction · 0.90
setFunction · 0.85
assertInMethod · 0.80
assertNotInMethod · 0.80
ObjectClass · 0.70
assertEqualMethod · 0.45
assertIsMethod · 0.45
itemsMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected