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

Method test_frame_stack

Lib/test/test_monitoring.py:339–369  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

337 self.assertEqual(c["raise"], c["exception_handled"] + c["unwind"])
338
339 def test_frame_stack(self):
340 self.maxDiff = None
341 stack = []
342 errors = []
343 seen = set()
344 def up(*args):
345 frame = sys._getframe(1)
346 if not stack:
347 errors.append("empty")
348 else:
349 expected = stack.pop()
350 if frame != expected:
351 errors.append(f" Popping {frame} expected {expected}")
352 def down(*args):
353 frame = sys._getframe(1)
354 stack.append(frame)
355 seen.add(frame.f_code)
356 def call(code, offset, callable, arg):
357 if not isinstance(callable, PY_CALLABLES):
358 stack.append(sys._getframe(1))
359 for event in UP_EVENTS:
360 sys.monitoring.register_callback(TEST_TOOL, event, up)
361 for event in DOWN_EVENTS:
362 sys.monitoring.register_callback(TEST_TOOL, event, down)
363 sys.monitoring.register_callback(TEST_TOOL, E.CALL, call)
364 sys.monitoring.set_events(TEST_TOOL, SIMPLE_EVENT_SET)
365 testfunc()
366 sys.monitoring.set_events(TEST_TOOL, 0)
367 self.assertEqual(errors, [])
368 self.assertEqual(stack, [sys._getframe()])
369 self.assertEqual(len(seen), 9)
370
371
372class CounterWithDisable:

Callers

nothing calls this directly

Calls 4

testfuncFunction · 0.90
setFunction · 0.85
register_callbackMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected