(self)
| 1379 | self.check_len_race(weakref.WeakValueDictionary, lambda k: (1, k)) |
| 1380 | |
| 1381 | def test_weak_values(self): |
| 1382 | # |
| 1383 | # This exercises d.copy(), d.items(), d[], del d[], len(d). |
| 1384 | # |
| 1385 | dict, objects = self.make_weak_valued_dict() |
| 1386 | for o in objects: |
| 1387 | self.assertEqual(weakref.getweakrefcount(o), 1) |
| 1388 | self.assertIs(o, dict[o.arg], |
| 1389 | "wrong object returned by weak dict!") |
| 1390 | items1 = list(dict.items()) |
| 1391 | items2 = list(dict.copy().items()) |
| 1392 | items1.sort() |
| 1393 | items2.sort() |
| 1394 | self.assertEqual(items1, items2, |
| 1395 | "cloning of weak-valued dictionary did not work!") |
| 1396 | del items1, items2 |
| 1397 | self.assertEqual(len(dict), self.COUNT) |
| 1398 | del objects[0] |
| 1399 | gc_collect() # For PyPy or other GCs. |
| 1400 | self.assertEqual(len(dict), self.COUNT - 1, |
| 1401 | "deleting object did not cause dictionary update") |
| 1402 | del objects, o |
| 1403 | gc_collect() # For PyPy or other GCs. |
| 1404 | self.assertEqual(len(dict), 0, |
| 1405 | "deleting the values did not clear the dictionary") |
| 1406 | # regression on SF bug #447152: |
| 1407 | dict = weakref.WeakValueDictionary() |
| 1408 | self.assertRaises(KeyError, dict.__getitem__, 1) |
| 1409 | dict[2] = C() |
| 1410 | gc_collect() # For PyPy or other GCs. |
| 1411 | self.assertRaises(KeyError, dict.__getitem__, 2) |
| 1412 | |
| 1413 | def test_weak_keys(self): |
| 1414 | # |
nothing calls this directly
no test coverage detected