(self)
| 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() |
nothing calls this directly
no test coverage detected