Skip to content

Commit

Permalink
Fix stream output (#294)
Browse files Browse the repository at this point in the history
* Fix stream output

* Fix tests
  • Loading branch information
davidbrochart authored Dec 2, 2024
1 parent 5de54c8 commit db70566
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion jupyter_ydoc/ynotebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def create_ycell(self, value: Dict[str, Any]) -> Map:
outputs = cell.get("outputs", [])
for idx, output in enumerate(outputs):
if output.get("output_type") == "stream":
output["text"] = Array(output.get("text", []))
text = output.get("text", "")
if isinstance(text, str):
ytext = Text(text)
else:
ytext = Text("".join(text))
output["text"] = ytext
outputs[idx] = Map(output)
cell["outputs"] = Array(outputs)
cell["execution_state"] = "idle"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pycrdt_yjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async def test_ypy_yjs_1(yws_server, yjs_client):
ydoc, Websocket(websocket, room_name)
):
output_text = ynotebook.ycells[0]["outputs"][0]["text"]
assert output_text.to_py() == ["Hello,"]
assert output_text.to_py() == "Hello,"
event = Event()

def callback(_event):
Expand All @@ -101,7 +101,7 @@ def callback(_event):
with move_on_after(10):
await event.wait()

assert output_text.to_py() == ["Hello,", " World!"]
assert output_text.to_py() == "Hello,", " World!"


def test_plotly_renderer():
Expand Down

0 comments on commit db70566

Please sign in to comment.