Python weakref.getweakrefs() Examples
The following are 30
code examples of weakref.getweakrefs().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
weakref
, or try the search function
.
Example #1
Source File: test_weakref.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #2
Source File: test_weakref.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertTrue(r1 is not r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIn(r1, refs) self.assertIn(r2, refs) self.assertIn(r3, refs)
Example #3
Source File: test_weakref.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [ref1], "list of refs does not match") del ref1 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertTrue(weakref.getweakrefs(1) == [], "list of refs does not match for int")
Example #4
Source File: test_weakref.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertTrue(r1 is not r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIn(r1, refs) self.assertIn(r2, refs) self.assertIn(r3, refs)
Example #5
Source File: test_weakref.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [ref1], "list of refs does not match") del ref1 gc.collect() self.assertTrue(weakref.getweakrefs(o) == [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertTrue(weakref.getweakrefs(1) == [], "list of refs does not match for int")
Example #6
Source File: test_weakref.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assert_(r1 is not r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assert_(r2 is refs[0]) self.assert_(r1 in refs[1:]) self.assert_(r3 in refs[1:])
Example #7
Source File: test_weakref.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 extra_collect() self.assert_(weakref.getweakrefs(o) == [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 extra_collect() self.assert_(weakref.getweakrefs(o) == [ref1], "list of refs does not match") del ref1 extra_collect() self.assert_(weakref.getweakrefs(o) == [], "list of refs not cleared") # assumes ints do not support weakrefs self.assert_(weakref.getweakrefs(1) == [], "list of refs does not match for int")
Example #8
Source File: test_weakref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #9
Source File: test_weakref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #10
Source File: test_weakref.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #11
Source File: test_weakref.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #12
Source File: test_weakref.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #13
Source File: test_weakref.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #14
Source File: test_weakref.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #15
Source File: test_weakref.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #16
Source File: test_weakref.py From oss-ftp with MIT License | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertIsNot(r1, r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertIs(r2, refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #17
Source File: test_weakref.py From oss-ftp with MIT License | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #18
Source File: test_weakref.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertEqual(weakref.getweakrefs(o), [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertEqual(weakref.getweakrefs(o), [ref1], "list of refs does not match") del ref1 self.assertEqual(weakref.getweakrefs(o), [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertEqual(weakref.getweakrefs(1), [], "list of refs does not match for int")
Example #19
Source File: test_weakref.py From BinderFilter with MIT License | 6 votes |
def test_getweakrefs(self): o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref1 self.assertTrue(weakref.getweakrefs(o) == [ref2], "list of refs does not match") o = C() ref1 = weakref.ref(o, self.callback) ref2 = weakref.ref(o, self.callback) del ref2 self.assertTrue(weakref.getweakrefs(o) == [ref1], "list of refs does not match") del ref1 self.assertTrue(weakref.getweakrefs(o) == [], "list of refs not cleared") # assumes ints do not support weakrefs self.assertTrue(weakref.getweakrefs(1) == [], "list of refs does not match for int")
Example #20
Source File: test_weakref.py From BinderFilter with MIT License | 6 votes |
def test_subclass_refs_dont_replace_standard_refs(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o) r2 = weakref.ref(o) self.assertTrue(r1 is not r2) self.assertEqual(weakref.getweakrefs(o), [r2, r1]) self.assertEqual(weakref.getweakrefcount(o), 2) r3 = MyRef(o) self.assertEqual(weakref.getweakrefcount(o), 3) refs = weakref.getweakrefs(o) self.assertEqual(len(refs), 3) self.assertTrue(r2 is refs[0]) self.assertIn(r1, refs[1:]) self.assertIn(r3, refs[1:])
Example #21
Source File: test_weakref.py From BinderFilter with MIT License | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertTrue(r1 is not r2) refs = weakref.getweakrefs(o) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #22
Source File: test_weakref.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertTrue(r1 is not r2) refs = list(weakref.getweakrefs(o)) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #23
Source File: test_weakref.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertIsNot(r1, r2) refs = weakref.getweakrefs(o) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #24
Source File: test_resurrection_attr_preserve.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_id_after_resurrection(self): l = ["ab"] rd = ResurrectionDummy() rd.toResurrect = l savedId = id(l) l = None rd = None runGC() #needed for Jython etc, even though no cyclic trash appears self.assertEqual(id(ResurrectionDummy.resurrected), savedId) del ResurrectionDummy.resurrected #todo: Check these test regarding to CPython behavior # def test_weakref_consistency_after_self_resurrection(self): # #fails in CPython # rd = SelfResurrectionDummy() # wref = weakref.ref(rd) # self.assertIn(wref, weakref.getweakrefs(rd)) # rd = None # runGC() #needed for Jython etc, even though no cyclic trash appears # self.asserIn(wref, weakref.getweakrefs(SelfResurrectionDummy.resurrected)) # for wref2 in weakref.getweakrefs(SelfResurrectionDummy.resurrected): # self.assertIs(wref2(), SelfResurrectionDummy.resurrected) # del SelfResurrectionDummy.resurrected # # def test_weakref_consistency_after_resurrection(self): # l = ReferentDummy("ab") # rd = ResurrectionDummy() # rd.toResurrect = l # wref = weakref.ref(l) # self.assertIn(wref, weakref.getweakrefs(l)) # l = None # rd = None # runGC() #needed for Jython etc, even though no cyclic trash appears # self.asserIn(wref, weakref.getweakrefs(ResurrectionDummy.resurrected)) # for wref2 in weakref.getweakrefs(ResurrectionDummy.resurrected): # self.assertIs(wref2(), ResurrectionDummy.resurrected) # del ResurrectionDummy.resurrected
Example #25
Source File: test_weakref.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertTrue(r1 is not r2) refs = list(weakref.getweakrefs(o)) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #26
Source File: test_resurrection_attr_preserve.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_id_after_resurrection(self): l = ["ab"] rd = ResurrectionDummy() rd.toResurrect = l savedId = id(l) l = None rd = None runGC() #needed for Jython etc, even though no cyclic trash appears self.assertEqual(id(ResurrectionDummy.resurrected), savedId) del ResurrectionDummy.resurrected #todo: Check these test regarding to CPython behavior # def test_weakref_consistency_after_self_resurrection(self): # #fails in CPython # rd = SelfResurrectionDummy() # wref = weakref.ref(rd) # self.assertIn(wref, weakref.getweakrefs(rd)) # rd = None # runGC() #needed for Jython etc, even though no cyclic trash appears # self.asserIn(wref, weakref.getweakrefs(SelfResurrectionDummy.resurrected)) # for wref2 in weakref.getweakrefs(SelfResurrectionDummy.resurrected): # self.assertIs(wref2(), SelfResurrectionDummy.resurrected) # del SelfResurrectionDummy.resurrected # # def test_weakref_consistency_after_resurrection(self): # l = ReferentDummy("ab") # rd = ResurrectionDummy() # rd.toResurrect = l # wref = weakref.ref(l) # self.assertIn(wref, weakref.getweakrefs(l)) # l = None # rd = None # runGC() #needed for Jython etc, even though no cyclic trash appears # self.asserIn(wref, weakref.getweakrefs(ResurrectionDummy.resurrected)) # for wref2 in weakref.getweakrefs(ResurrectionDummy.resurrected): # self.assertIs(wref2(), ResurrectionDummy.resurrected) # del ResurrectionDummy.resurrected
Example #27
Source File: test_weakref.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assert_(r1 is not r2) refs = weakref.getweakrefs(o) self.assert_(r1 in refs) self.assert_(r2 in refs)
Example #28
Source File: test_weakref.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertIsNot(r1, r2) refs = weakref.getweakrefs(o) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #29
Source File: test_weakref.py From oss-ftp with MIT License | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertIsNot(r1, r2) refs = weakref.getweakrefs(o) self.assertIn(r1, refs) self.assertIn(r2, refs)
Example #30
Source File: test_weakref.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_subclass_refs_dont_conflate_callbacks(self): class MyRef(weakref.ref): pass o = Object(42) r1 = MyRef(o, id) r2 = MyRef(o, str) self.assertIsNot(r1, r2) refs = weakref.getweakrefs(o) self.assertIn(r1, refs) self.assertIn(r2, refs)