当前位置: 首页>>代码示例>>Python>>正文


Python weakref.getweakrefs方法代码示例

本文整理汇总了Python中weakref.getweakrefs方法的典型用法代码示例。如果您正苦于以下问题:Python weakref.getweakrefs方法的具体用法?Python weakref.getweakrefs怎么用?Python weakref.getweakrefs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weakref的用法示例。


在下文中一共展示了weakref.getweakrefs方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_getweakrefs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_weakref.py

示例2: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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:]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_weakref.py

示例3: test_getweakrefs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:24,代码来源:test_weakref.py

示例4: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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:]) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:18,代码来源:test_weakref.py

示例5: test_getweakrefs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:27,代码来源:test_weakref.py

示例6: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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:]) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:test_weakref.py

示例7: test_getweakrefs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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") 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:27,代码来源:test_weakref.py

示例8: test_subclass_refs_dont_replace_standard_refs

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:18,代码来源:test_weakref.py

示例9: test_subclass_refs_dont_conflate_callbacks

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_weakref.py

示例10: test_subclass_refs_dont_conflate_callbacks

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:12,代码来源:test_weakref.py

示例11: test_subclass_refs_dont_conflate_callbacks

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:test_weakref.py

示例12: test_id_after_resurrection

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:39,代码来源:test_resurrection_attr_preserve.py

示例13: test_subclass_refs_dont_conflate_callbacks

# 需要导入模块: import weakref [as 别名]
# 或者: from weakref import getweakrefs [as 别名]
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) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:12,代码来源:test_weakref.py


注:本文中的weakref.getweakrefs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。