From 8eac1b40b3e4269889ba519389b2954181fdf40d Mon Sep 17 00:00:00 2001 From: David Brochart Date: Thu, 18 Apr 2024 15:37:07 +0200 Subject: [PATCH] Remove output trailing newline --- plugins/kernels/fps_kernels/kernel_driver/driver.py | 7 +++++-- tests/test_server.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/kernels/fps_kernels/kernel_driver/driver.py b/plugins/kernels/fps_kernels/kernel_driver/driver.py index 6c2fba20..d1761b77 100644 --- a/plugins/kernels/fps_kernels/kernel_driver/driver.py +++ b/plugins/kernels/fps_kernels/kernel_driver/driver.py @@ -223,6 +223,9 @@ async def _handle_outputs(self, outputs: Array, msg: Dict[str, Any]): if msg_type == "stream": with outputs.doc.transaction(): # TODO: uncomment when changes are made in jupyter-ydoc + text = content["text"] + if text.endswith((os.linesep, "\n")): + text = text[:-1] if (not outputs) or (outputs[-1]["name"] != content["name"]): # type: ignore outputs.append( #Map( @@ -235,13 +238,13 @@ async def _handle_outputs(self, outputs: Array, msg: Dict[str, Any]): { "name": content["name"], "output_type": msg_type, - "text": [content["text"]], + "text": [text], } ) else: #outputs[-1]["text"].append(content["text"]) # type: ignore last_output = outputs[-1] - last_output["text"].append(content["text"]) # type: ignore + last_output["text"].append(text) # type: ignore outputs[-1] = last_output elif msg_type in ("display_data", "execute_result"): if "application/vnd.jupyter.ywidget-view+json" in content["data"]: diff --git a/tests/test_server.py b/tests/test_server.py index bc2325d4..0ba0cc03 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -113,7 +113,7 @@ async def test_rest_api(start_jupyverse): } ] assert cells[1]["outputs"] == [ - {"name": "stdout", "output_type": "stream", "text": ["Hello World!\n"]} + {"name": "stdout", "output_type": "stream", "text": ["Hello World!"]} ] assert cells[2]["outputs"] == [ {