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 ccdd7f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 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
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -105,7 +106,7 @@ frontend = ["jupyterlab", "retrolab"]
auth = ["noauth", "auth", "auth_fief", "auth_jupyterhub"]

[tool.hatch.envs.dev.scripts]
test = "pytest ./tests plugins/webdav/tests -v --reruns 5 --timeout=60"
test = "pytest ./tests plugins/webdav/tests -v --timeout=60"
lint = [
"ruff format jupyverse jupyverse_api notebooks plugins tests",
"ruff check jupyverse jupyverse_api notebooks plugins tests --fix",
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
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 ccdd7f9

Please sign in to comment.