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