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

Function test_monkeypatch

Lib/test/audit-tests.py:159–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

157
158
159def test_monkeypatch():
160 class A:
161 pass
162
163 class B:
164 pass
165
166 class C(A):
167 pass
168
169 a = A()
170
171 with TestHook() as hook:
172 # Catch name changes
173 C.__name__ = "X"
174 # Catch type changes
175 C.__bases__ = (B,)
176 # Ensure bypassing __setattr__ is still caught
177 type.__dict__["__bases__"].__set__(C, (B,))
178 # Catch attribute replacement
179 C.__init__ = B.__init__
180 # Catch attribute addition
181 C.new_attr = 123
182 # Catch class changes
183 a.__class__ = B
184
185 actual = [(a[0], a[1]) for e, a in hook.seen if e == "object.__setattr__"]
186 assertSequenceEqual(
187 [(C, "__name__"), (C, "__bases__"), (C, "__bases__"), (a, "__class__")], actual
188 )
189
190
191def test_open(testfn):

Callers

nothing calls this directly

Calls 4

assertSequenceEqualFunction · 0.85
AClass · 0.70
TestHookClass · 0.70
__set__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…