MCPcopy Index your code
hub / github.com/python/cpython / test_subclass_refs

Method test_subclass_refs

Lib/test/test_weakref.py:1076–1092  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1074class SubclassableWeakrefTestCase(TestBase):
1075
1076 def test_subclass_refs(self):
1077 class MyRef(weakref.ref):
1078 def __init__(self, ob, callback=None, value=42):
1079 self.value = value
1080 super().__init__(ob, callback)
1081 def __call__(self):
1082 self.called = True
1083 return super().__call__()
1084 o = Object("foo")
1085 mr = MyRef(o, value=24)
1086 self.assertIs(mr(), o)
1087 self.assertTrue(mr.called)
1088 self.assertEqual(mr.value, 24)
1089 del o
1090 gc_collect() # For PyPy or other GCs.
1091 self.assertIsNone(mr())
1092 self.assertTrue(mr.called)
1093
1094 def test_subclass_refs_dont_replace_standard_refs(self):
1095 class MyRef(weakref.ref):

Callers

nothing calls this directly

Calls 8

gc_collectFunction · 0.90
MyRefClass · 0.85
mrFunction · 0.85
assertTrueMethod · 0.80
assertIsNoneMethod · 0.80
ObjectClass · 0.70
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected