(self, dict_type, cons)
| 1323 | NUM_THREADED_ITERATIONS = 100000 |
| 1324 | |
| 1325 | def check_len_cycles(self, dict_type, cons): |
| 1326 | N = 20 |
| 1327 | items = [RefCycle() for i in range(N)] |
| 1328 | dct = dict_type(cons(o) for o in items) |
| 1329 | # Keep an iterator alive |
| 1330 | it = dct.items() |
| 1331 | try: |
| 1332 | next(it) |
| 1333 | except StopIteration: |
| 1334 | pass |
| 1335 | del items |
| 1336 | gc.collect() |
| 1337 | n1 = len(dct) |
| 1338 | del it |
| 1339 | gc.collect() |
| 1340 | n2 = len(dct) |
| 1341 | # one item may be kept alive inside the iterator |
| 1342 | self.assertIn(n1, (0, 1)) |
| 1343 | self.assertEqual(n2, 0) |
| 1344 | |
| 1345 | def test_weak_keyed_len_cycles(self): |
| 1346 | self.check_len_cycles(weakref.WeakKeyDictionary, lambda k: (k, 1)) |
no test coverage detected