Lines Matching defs:hook

14     """Used in standard hook tests to collect any logged events.
83 with TestHook() as hook:
85 assertEqual(hook.seen[0][0], "test_event")
86 assertEqual(hook.seen[0][1], (1, 2, 3))
90 # Raising an exception should prevent a new hook from being added,
100 # Raising BaseException will propagate out when adding a hook
105 # Adding this next hook should raise BaseException
115 with TestHook() as hook:
126 actual = [(a[0], a[1]) for e, a in hook.seen if e == "marshal.dumps"]
129 actual = [a[0] for e, a in hook.seen if e == "marshal.loads"]
132 actual = [e for e, a in hook.seen if e == "marshal.load"]
146 # Before we add the hook, ensure our malicious pickle loads
149 with TestHook(raise_on_events="pickle.find_class") as hook:
151 # With the hook enabled, loading globals is not allowed
169 with TestHook() as hook:
183 actual = [(a[0], a[1]) for e, a in hook.seen if e == "object.__setattr__"]
200 with TestHook(raise_on_events={"open"}) as hook:
213 actual_mode = [(a[0], a[1]) for e, a in hook.seen if e == "open" and a[1]]
214 actual_flag = [(a[0], a[2]) for e, a in hook.seen if e == "open" and not a[1]]
241 with TestHook() as hook:
246 hook.__cantrace__ = False
250 hook.__cantrace__ = True
254 hook.__cantrace__ = 1
258 hook.__cantrace__ = 0
268 with TestHook() as hook:
270 assertEqual(hook.seen[0][1][:2], (-1, 8))
278 def hook(event, args):
286 sys.addaudithook(hook)
297 def hook(event, args):
303 sys.addaudithook(hook)
305 write_unraisable_exc(RuntimeError("nonfatal-error"), "for audit hook test", None)
311 def hook(event, args):
316 sys.addaudithook(hook)
334 def hook(event, args):
338 sys.addaudithook(hook)
356 def hook(event, args):
360 sys.addaudithook(hook)
374 def hook(event, args):
378 sys.addaudithook(hook)
392 def hook(event, *args):
396 sys.addaudithook(hook)
414 def hook(event, args):
418 sys.addaudithook(hook)
425 def hook(event, args):
429 sys.addaudithook(hook)
446 hook = lambda *a: None
447 sys.addaudithook(hook)
451 assert hook not in o