MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / test_hook

Function test_hook

test/mitmproxy/test_hooks.py:8–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6
7
8def test_hook():
9 with pytest.raises(TypeError, match="may not be instantiated directly"):
10 hooks.Hook()
11
12 class NoDataClass(hooks.Hook):
13 pass
14
15 with pytest.raises(TypeError, match="not a dataclass"):
16 NoDataClass()
17
18 @dataclass
19 class FooHook(hooks.Hook):
20 data: bytes
21
22 e = FooHook(b"foo")
23 assert repr(e)
24 assert e.args() == [b"foo"]
25 assert FooHook in hooks.all_hooks.values()
26
27 with pytest.warns(RuntimeWarning, match="Two conflicting event classes"):
28
29 @dataclass
30 class FooHook2(hooks.Hook):
31 name = "foo"
32
33 @dataclass
34 class AnotherABC(hooks.Hook):
35 name = ""
36
37 assert AnotherABC not in hooks.all_hooks.values()

Callers

nothing calls this directly

Calls 4

NoDataClassClass · 0.85
FooHookClass · 0.85
argsMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…