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

Class TestHook

Lib/test/audit-tests.py:15–47  ·  view source on GitHub ↗

Used in standard hook tests to collect any logged events. Should be used in a with block to ensure that it has no impact after the test completes.

Source from the content-addressed store, hash-verified

13
14
15class TestHook:
16 """Used in standard hook tests to collect any logged events.
17
18 Should be used in a with block to ensure that it has no impact
19 after the test completes.
20 """
21
22 def __init__(self, raise_on_events=None, exc_type=RuntimeError):
23 self.raise_on_events = raise_on_events or ()
24 self.exc_type = exc_type
25 self.seen = []
26 self.closed = False
27
28 def __enter__(self, *a):
29 sys.addaudithook(self)
30 return self
31
32 def __exit__(self, *a):
33 self.close()
34
35 def close(self):
36 self.closed = True
37
38 @property
39 def seen_events(self):
40 return [i[0] for i in self.seen]
41
42 def __call__(self, event, args):
43 if self.closed:
44 return
45 self.seen.append((event, args))
46 if event in self.raise_on_events:
47 raise self.exc_type("saw event " + event)
48
49
50# Simple helpers, since we are not in unittest here

Callers 14

test_basicFunction · 0.70
test_block_add_hookFunction · 0.70
test_marshalFunction · 0.70
test_pickleFunction · 0.70
test_monkeypatchFunction · 0.70
test_openFunction · 0.70
test_cantraceFunction · 0.70
test_mmapFunction · 0.70
test_posixsubprocessFunction · 0.70
test_import_moduleFunction · 0.70

Calls

no outgoing calls

Tested by 14

test_basicFunction · 0.56
test_block_add_hookFunction · 0.56
test_marshalFunction · 0.56
test_pickleFunction · 0.56
test_monkeypatchFunction · 0.56
test_openFunction · 0.56
test_cantraceFunction · 0.56
test_mmapFunction · 0.56
test_posixsubprocessFunction · 0.56
test_import_moduleFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…