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

Method check_disable

Lib/test/test_monitoring.py:2387–2420  ·  view source on GitHub ↗
(self, event, func, args, expected)

Source from the content-addressed store, hash-verified

2385 E.EXCEPTION_HANDLED, E.PY_UNWIND }
2386
2387 def check_disable(self, event, func, args, expected):
2388 try:
2389 counter = CounterWithDisable()
2390 sys.monitoring.register_callback(TEST_TOOL, event, counter)
2391 if event == E.C_RETURN or event == E.C_RAISE:
2392 sys.monitoring.set_events(TEST_TOOL, E.CALL)
2393 else:
2394 sys.monitoring.set_events(TEST_TOOL, event)
2395 event_value = int(math.log2(event))
2396 with self.Scope(self.codelike, event_value):
2397 counter.count = 0
2398 func(*args)
2399 self.assertEqual(counter.count, expected)
2400 counter.disable = True
2401 if event in self.CANNOT_DISABLE:
2402 # use try-except rather then assertRaises to avoid
2403 # events from framework code
2404 try:
2405 counter.count = 0
2406 func(*args)
2407 self.assertEqual(counter.count, expected)
2408 except ValueError:
2409 pass
2410 else:
2411 self.Error("Expected a ValueError")
2412 else:
2413 counter.count = 0
2414 func(*args)
2415 self.assertEqual(counter.count, expected)
2416 counter.count = 0
2417 func(*args)
2418 self.assertEqual(counter.count, expected - 1)
2419 finally:
2420 sys.monitoring.set_events(TEST_TOOL, 0)
2421
2422 def test_disable_event(self):
2423 for expected, event, function, *args in self.cases:

Callers 1

test_disable_eventMethod · 0.95

Calls 4

CounterWithDisableClass · 0.85
funcFunction · 0.70
register_callbackMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected