Skip to content

Commit cf195be

Browse files
authored
Fix build and CI (#50)
* Fix build and CI * Lint * Downgrade eslint * Add pytest-asyncio * Fix failing test * Fix flaky tests by running them in isolation with `pytest-forked` * Restore lock file in ui-tests * Add a log for testing
1 parent b99f3c5 commit cf195be

File tree

9 files changed

+15314
-226
lines changed

9 files changed

+15314
-226
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)
32

43
[![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%20Sponsor&message=%E2%9D%A4&logo=GitHub&style=flat&color=1ABC9C)](https://github.com/sponsors/datalayer)

jupyter_server_nbmodel/tests/test_handlers.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121

2222
REQUEST_REGEX = re.compile(r"^/api/kernels/\w+-\w+-\w+-\w+-\w+/requests/\w+-\w+-\w+-\w+-\w+$")
23+
ANSI_REGEX = re.compile("\x1b\\[(.*?)([@-~])")
24+
25+
26+
def strip_ansi(text: str):
27+
return ANSI_REGEX.sub("", text)
2328

2429

2530
async def _wait_request(fetch, endpoint: str):
@@ -122,7 +127,17 @@ async def test_post_execute(jp_fetch, pending_kernel_is_ready, snippet, output):
122127
(
123128
(
124129
"1 / 0",
125-
'{"output_type": "error", "ename": "ZeroDivisionError", "evalue": "division by zero", "traceback": ["\\u001b[0;31m---------------------------------------------------------------------------\\u001b[0m", "\\u001b[0;31mZeroDivisionError\\u001b[0m Traceback (most recent call last)", "Cell \\u001b[0;32mIn[1], line 1\\u001b[0m\\n\\u001b[0;32m----> 1\\u001b[0m \\u001b[38;5;241;43m1\\u001b[39;49m\\u001b[43m \\u001b[49m\\u001b[38;5;241;43m/\\u001b[39;49m\\u001b[43m \\u001b[49m\\u001b[38;5;241;43m0\\u001b[39;49m\\n", "\\u001b[0;31mZeroDivisionError\\u001b[0m: division by zero"]}', # noqa: E501
130+
{
131+
"output_type": "error",
132+
"ename": "ZeroDivisionError",
133+
"evalue": "division by zero",
134+
"traceback": [
135+
"---------------------------------------------------------------------------",
136+
"ZeroDivisionError Traceback (most recent call last)",
137+
"Cell In[1], line 1\n----> 1 1 / 0\n",
138+
"ZeroDivisionError: division by zero"
139+
]
140+
},
126141
),
127142
),
128143
)
@@ -146,17 +161,27 @@ async def test_post_erroneous_execute(jp_fetch, pending_kernel_is_ready, snippet
146161

147162
assert response.code == 200
148163
payload = json.loads(response.body)
164+
outputs = payload["outputs"]
165+
del payload["outputs"]
149166
assert payload == {
150167
"status": "error",
151-
"execution_count": 1,
152-
"outputs": f"[{output}]",
168+
"execution_count": 1
153169
}
170+
outputs = json.loads(outputs)
171+
for output in outputs:
172+
output["traceback"] = [
173+
strip_ansi(line)
174+
for line in output["traceback"]
175+
]
176+
177+
assert outputs == [output]
154178

155179
response2 = await jp_fetch("api", "kernels", kernel["id"], method="DELETE")
156180
assert response2.code == 204
157181

158182
await asyncio.sleep(1)
159183

184+
160185
@pytest.mark.asyncio
161186
async def test_kernel_worker_reports_error(monkeypatch):
162187
# Patch _execute_snippet to raise an error
@@ -196,6 +221,7 @@ async def fake_execute(client, ydoc, snippet, metadata, stdin_hook):
196221
assert "error" in results[uid], f"Expected an 'error' key in results[{uid!r}]"
197222
assert "simulated failure" in results[uid]["error"]
198223

224+
199225
@pytest.mark.timeout(TEST_TIMEOUT)
200226
async def test_execution_timing_metadata(jp_root_dir, jp_fetch, pending_kernel_is_ready, rtc_create_notebook, jp_serverapp):
201227
snippet = "a = 1"

0 commit comments

Comments
 (0)