MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_weak_keys

Method test_weak_keys

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

Source from the content-addressed store, hash-verified

1393 self.assertRaises(KeyError, dict.__getitem__, 2)
1394
1395 def test_weak_keys(self):
1396 #
1397 # This exercises d.copy(), d.items(), d[] = v, d[], del d[],
1398 # len(d), k in d.
1399 #
1400 dict, objects = self.make_weak_keyed_dict()
1401 for o in objects:
1402 self.assertEqual(weakref.getweakrefcount(o), 1,
1403 "wrong number of weak references to %r!" % o)
1404 self.assertIs(o.arg, dict[o],
1405 "wrong object returned by weak dict!")
1406 items1 = dict.items()
1407 items2 = dict.copy().items()
1408 self.assertEqual(set(items1), set(items2),
1409 "cloning of weak-keyed dictionary did not work!")
1410 del items1, items2
1411 self.assertEqual(len(dict), self.COUNT)
1412 del objects[0]
1413 gc_collect() # For PyPy or other GCs.
1414 self.assertEqual(len(dict), (self.COUNT - 1),
1415 "deleting object did not cause dictionary update")
1416 del objects, o
1417 gc_collect() # For PyPy or other GCs.
1418 self.assertEqual(len(dict), 0,
1419 "deleting the keys did not clear the dictionary")
1420 o = Object(42)
1421 dict[o] = "What is the meaning of the universe?"
1422 self.assertIn(o, dict)
1423 self.assertNotIn(34, dict)
1424
1425 def test_weak_keyed_iters(self):
1426 dict, objects = self.make_weak_keyed_dict()

Callers

nothing calls this directly

Calls 11

make_weak_keyed_dictMethod · 0.95
gc_collectFunction · 0.90
setFunction · 0.85
lenFunction · 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