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

Method test_weak_values

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

Source from the content-addressed store, hash-verified

1361 self.check_len_race(weakref.WeakValueDictionary, lambda k: (1, k))
1362
1363 def test_weak_values(self):
1364 #
1365 # This exercises d.copy(), d.items(), d[], del d[], len(d).
1366 #
1367 dict, objects = self.make_weak_valued_dict()
1368 for o in objects:
1369 self.assertEqual(weakref.getweakrefcount(o), 1)
1370 self.assertIs(o, dict[o.arg],
1371 "wrong object returned by weak dict!")
1372 items1 = list(dict.items())
1373 items2 = list(dict.copy().items())
1374 items1.sort()
1375 items2.sort()
1376 self.assertEqual(items1, items2,
1377 "cloning of weak-valued dictionary did not work!")
1378 del items1, items2
1379 self.assertEqual(len(dict), self.COUNT)
1380 del objects[0]
1381 gc_collect() # For PyPy or other GCs.
1382 self.assertEqual(len(dict), self.COUNT - 1,
1383 "deleting object did not cause dictionary update")
1384 del objects, o
1385 gc_collect() # For PyPy or other GCs.
1386 self.assertEqual(len(dict), 0,
1387 "deleting the values did not clear the dictionary")
1388 # regression on SF bug #447152:
1389 dict = weakref.WeakValueDictionary()
1390 self.assertRaises(KeyError, dict.__getitem__, 1)
1391 dict[2] = C()
1392 gc_collect() # For PyPy or other GCs.
1393 self.assertRaises(KeyError, dict.__getitem__, 2)
1394
1395 def test_weak_keys(self):
1396 #

Callers

nothing calls this directly

Calls 12

make_weak_valued_dictMethod · 0.95
itemsMethod · 0.95
copyMethod · 0.95
gc_collectFunction · 0.90
listClass · 0.85
lenFunction · 0.85
CClass · 0.70
assertEqualMethod · 0.45
assertIsMethod · 0.45
itemsMethod · 0.45
sortMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected