(self)
| 267 | "ref2 should be dead after deleting object reference") |
| 268 | |
| 269 | def test_ref_reuse(self): |
| 270 | o = C() |
| 271 | ref1 = weakref.ref(o) |
| 272 | # create a proxy to make sure that there's an intervening creation |
| 273 | # between these two; it should make no difference |
| 274 | proxy = weakref.proxy(o) |
| 275 | ref2 = weakref.ref(o) |
| 276 | self.assertIs(ref1, ref2, |
| 277 | "reference object w/out callback should be re-used") |
| 278 | |
| 279 | o = C() |
| 280 | proxy = weakref.proxy(o) |
| 281 | ref1 = weakref.ref(o) |
| 282 | ref2 = weakref.ref(o) |
| 283 | self.assertIs(ref1, ref2, |
| 284 | "reference object w/out callback should be re-used") |
| 285 | self.assertEqual(weakref.getweakrefcount(o), 2, |
| 286 | "wrong weak ref count for object") |
| 287 | del proxy |
| 288 | gc_collect() # For PyPy or other GCs. |
| 289 | self.assertEqual(weakref.getweakrefcount(o), 1, |
| 290 | "wrong weak ref count for object after deleting proxy") |
| 291 | |
| 292 | def test_proxy_reuse(self): |
| 293 | o = C() |
nothing calls this directly
no test coverage detected