We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Missing documentation about unit testing inline scripts
At the company I work on we are developing some inline scripts to use internally.

We are struggling to create test for our scripts because the only code we found to test scripts are the ones at [/mitmproxy/mitmproxy/blob/v0.17/test/mitmproxy/test_examples.py](/mitmproxy/mitmproxy/blob/v0.17/test/mitmproxy/test_examples.py).

The examples are quite good but real documentation is missing for the ones who wants to unit test.

Is there another place where I can find better (maybe more advanced) test examples ?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mitmproxy/events.py`
Content:
```
1 from mitmproxy import controller
2 from mitmproxy import http
3 from mitmproxy import tcp
4 from mitmproxy import websocket
5 
6 Events = frozenset([
7     "clientconnect",
8     "clientdisconnect",
9     "serverconnect",
10     "serverdisconnect",
11 
12     "tcp_start",
13     "tcp_message",
14     "tcp_error",
15     "tcp_end",
16 
17     "http_connect",
18     "request",
19     "requestheaders",
20     "response",
21     "responseheaders",
22     "error",
23 
24     "intercept",
25     "resume",
26 
27     "websocket_handshake",
28     "websocket_start",
29     "websocket_message",
30     "websocket_error",
31     "websocket_end",
32 
33     "next_layer",
34 
35     "configure",
36     "done",
37     "log",
38     "start",
39     "tick",
40 ])
41 
42 
43 def event_sequence(f):
44     if isinstance(f, http.HTTPFlow):
45         if f.request:
46             yield "requestheaders", f
47             yield "request", f
48         if f.response:
49             yield "responseheaders", f
50             yield "response", f
51         if f.error:
52             yield "error", f
53     elif isinstance(f, websocket.WebSocketFlow):
54         messages = f.messages
55         f.messages = []
56         f.reply = controller.DummyReply()
57         yield "websocket_start", f
58         while messages:
59             f.messages.append(messages.pop(0))
60             yield "websocket_message", f
61         if f.error:
62             yield "websocket_error", f
63         yield "websocket_end", f
64     elif isinstance(f, tcp.TCPFlow):
65         messages = f.messages
66         f.messages = []
67         f.reply = controller.DummyReply()
68         yield "tcp_start", f
69         while messages:
70             f.messages.append(messages.pop(0))
71             yield "tcp_message", f
72         if f.error:
73             yield "tcp_error", f
74         yield "tcp_end", f
75     else:
76         raise NotImplementedError
77
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mitmproxy/events.py b/mitmproxy/events.py
--- a/mitmproxy/events.py
+++ b/mitmproxy/events.py
@@ -21,9 +21,6 @@
     "responseheaders",
     "error",
 
-    "intercept",
-    "resume",
-
     "websocket_handshake",
     "websocket_start",
     "websocket_message",

{"golden_diff": "diff --git a/mitmproxy/events.py b/mitmproxy/events.py\n--- a/mitmproxy/events.py\n+++ b/mitmproxy/events.py\n@@ -21,9 +21,6 @@\n     \"responseheaders\",\n     \"error\",\n \n-    \"intercept\",\n-    \"resume\",\n-\n     \"websocket_handshake\",\n     \"websocket_start\",\n     \"websocket_message\",\n", "issue": "Missing documentation about unit testing inline scripts\nAt the company I work on we are developing some inline scripts to use internally.\n\nWe are struggling to create test for our scripts because the only code we found to test scripts are the ones at [/mitmproxy/mitmproxy/blob/v0.17/test/mitmproxy/test_examples.py](/mitmproxy/mitmproxy/blob/v0.17/test/mitmproxy/test_examples.py).\n\nThe examples are quite good but real documentation is missing for the ones who wants to unit test.\n\nIs there another place where I can find better (maybe more advanced) test examples ?\n\n", "before_files": [{"content": "from mitmproxy import controller\nfrom mitmproxy import http\nfrom mitmproxy import tcp\nfrom mitmproxy import websocket\n\nEvents = frozenset([\n    \"clientconnect\",\n    \"clientdisconnect\",\n    \"serverconnect\",\n    \"serverdisconnect\",\n\n    \"tcp_start\",\n    \"tcp_message\",\n    \"tcp_error\",\n    \"tcp_end\",\n\n    \"http_connect\",\n    \"request\",\n    \"requestheaders\",\n    \"response\",\n    \"responseheaders\",\n    \"error\",\n\n    \"intercept\",\n    \"resume\",\n\n    \"websocket_handshake\",\n    \"websocket_start\",\n    \"websocket_message\",\n    \"websocket_error\",\n    \"websocket_end\",\n\n    \"next_layer\",\n\n    \"configure\",\n    \"done\",\n    \"log\",\n    \"start\",\n    \"tick\",\n])\n\n\ndef event_sequence(f):\n    if isinstance(f, http.HTTPFlow):\n        if f.request:\n            yield \"requestheaders\", f\n            yield \"request\", f\n        if f.response:\n            yield \"responseheaders\", f\n            yield \"response\", f\n        if f.error:\n            yield \"error\", f\n    elif isinstance(f, websocket.WebSocketFlow):\n        messages = f.messages\n        f.messages = []\n        f.reply = controller.DummyReply()\n        yield \"websocket_start\", f\n        while messages:\n            f.messages.append(messages.pop(0))\n            yield \"websocket_message\", f\n        if f.error:\n            yield \"websocket_error\", f\n        yield \"websocket_end\", f\n    elif isinstance(f, tcp.TCPFlow):\n        messages = f.messages\n        f.messages = []\n        f.reply = controller.DummyReply()\n        yield \"tcp_start\", f\n        while messages:\n            f.messages.append(messages.pop(0))\n            yield \"tcp_message\", f\n        if f.error:\n            yield \"tcp_error\", f\n        yield \"tcp_end\", f\n    else:\n        raise NotImplementedError\n", "path": "mitmproxy/events.py"}], "after_files": [{"content": "from mitmproxy import controller\nfrom mitmproxy import http\nfrom mitmproxy import tcp\nfrom mitmproxy import websocket\n\nEvents = frozenset([\n    \"clientconnect\",\n    \"clientdisconnect\",\n    \"serverconnect\",\n    \"serverdisconnect\",\n\n    \"tcp_start\",\n    \"tcp_message\",\n    \"tcp_error\",\n    \"tcp_end\",\n\n    \"http_connect\",\n    \"request\",\n    \"requestheaders\",\n    \"response\",\n    \"responseheaders\",\n    \"error\",\n\n    \"websocket_handshake\",\n    \"websocket_start\",\n    \"websocket_message\",\n    \"websocket_error\",\n    \"websocket_end\",\n\n    \"next_layer\",\n\n    \"configure\",\n    \"done\",\n    \"log\",\n    \"start\",\n    \"tick\",\n])\n\n\ndef event_sequence(f):\n    if isinstance(f, http.HTTPFlow):\n        if f.request:\n            yield \"requestheaders\", f\n            yield \"request\", f\n        if f.response:\n            yield \"responseheaders\", f\n            yield \"response\", f\n        if f.error:\n            yield \"error\", f\n    elif isinstance(f, websocket.WebSocketFlow):\n        messages = f.messages\n        f.messages = []\n        f.reply = controller.DummyReply()\n        yield \"websocket_start\", f\n        while messages:\n            f.messages.append(messages.pop(0))\n            yield \"websocket_message\", f\n        if f.error:\n            yield \"websocket_error\", f\n        yield \"websocket_end\", f\n    elif isinstance(f, tcp.TCPFlow):\n        messages = f.messages\n        f.messages = []\n        f.reply = controller.DummyReply()\n        yield \"tcp_start\", f\n        while messages:\n            f.messages.append(messages.pop(0))\n            yield \"tcp_message\", f\n        if f.error:\n            yield \"tcp_error\", f\n        yield \"tcp_end\", f\n    else:\n        raise NotImplementedError\n", "path": "mitmproxy/events.py"}]}