MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_frame_stack

Method test_frame_stack

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

testfuncFunction · 0.90
setFunction · 0.85
lenFunction · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected