Skip to content

Commit

Permalink
Use ypywidgets-textual in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Nov 7, 2023
1 parent 350c042 commit 00297b7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
16 changes: 13 additions & 3 deletions plugins/kernels/fps_kernels/kernel_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,19 @@ async def _handle_outputs(self, outputs: Array, msg: Dict[str, Any]):
msg_type = msg["header"]["msg_type"]
content = msg["content"]
if msg_type == "stream":
if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore
outputs.append({"name": content["name"], "output_type": msg_type, "text": []})
outputs[-1]["text"].append(content["text"]) # type: ignore
with outputs.doc.transaction():
if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore
outputs.append(
Map(
{
"name": content["name"],
"output_type": msg_type,
"text": Array([content["text"]]),
}
)
)
else:
outputs[-1]["text"].append(content["text"]) # type: ignore
elif msg_type in ("display_data", "execute_result"):
if "application/vnd.jupyter.ywidget-view+json" in content["data"]:
# this is a collaborative widget
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test = [
"websockets",
"ipykernel",
"ypywidgets >=0.5.0,<0.6.0",
"ypywidgets-textual",
]
docs = [ "mkdocs", "mkdocs-material" ]

Expand Down
12 changes: 1 addition & 11 deletions tests/data/notebook1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@
"execution_count": null,
"outputs": [],
"id": "a7243792-6f06-4462-a6b5-7e9ec604348e",
"source": "from ypywidgets import Widget, reactive",
"source": "from ypywidgets_textual.switch import Switch",
"cell_type": "code",
"metadata": {
"trusted": false
}
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"id": "dc428ca1-d2f1-4dc1-8811-6be77103d683",
"execution_count": null,
"source": "class Switch(Widget):\n value = reactive(False)\n def __init__(self) -> None:\n super().__init__(primary=True)\n def toggle(self):\n self.value = not self.value",
"outputs": []
},
{
"id": "a7243792-6f06-4462-a6b5-7e9ec604348f",
"source": "switch = Switch()\nswitch",
Expand Down
5 changes: 2 additions & 3 deletions tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async def recv(self) -> bytes:
return bytes(b)


@pytest.mark.skip(reason="FIXME")
@pytest.mark.asyncio
@pytest.mark.parametrize("auth_mode", ("noauth",))
async def test_execute(auth_mode, unused_tcp_port):
Expand Down Expand Up @@ -109,7 +108,7 @@ def callback(aevent, events, event):
# wait for file to be loaded and Y model to be created in server and client
await asyncio.sleep(0.5)
# execute notebook
for cell_idx in range(3):
for cell_idx in range(2):
response = await http.post(
f"{url}/api/kernels/{kernel_id}/execute",
json={
Expand All @@ -131,7 +130,7 @@ def callback(aevent, events, event):
f"{url}/api/kernels/{kernel_id}/execute",
json={
"document_id": document_id,
"cell_idx": 3,
"cell_idx": 2,
}
)
await task
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def callback(aevent, events, event):
# wait for file to be loaded and Y model to be created in server and client
await asyncio.sleep(0.5)
# execute notebook
for cell_idx in range(3):
for cell_idx in range(2):
response = requests.post(
f"{url}/api/kernels/{kernel_id}/execute",
data=json.dumps(
Expand All @@ -200,7 +200,7 @@ def callback(aevent, events, event):
data=json.dumps(
{
"document_id": document_id,
"cell_idx": 3,
"cell_idx": 2,
}
),
)
Expand Down

0 comments on commit 00297b7

Please sign in to comment.