From da946b05b7317229be27539e8e009eecf15660bf Mon Sep 17 00:00:00 2001 From: Carlos Herrero <26092748+hbcarlos@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:09:50 +0200 Subject: [PATCH 1/3] Fix empty YNotebook --- jupyter_ydoc/ynotebook.py | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jupyter_ydoc/ynotebook.py b/jupyter_ydoc/ynotebook.py index 47ae466..b4bd0ad 100644 --- a/jupyter_ydoc/ynotebook.py +++ b/jupyter_ydoc/ynotebook.py @@ -221,8 +221,8 @@ def get(self) -> Dict: return dict( cells=cells, metadata=meta.get("metadata", {}), - nbformat=int(meta.get("nbformat", 0)), - nbformat_minor=int(meta.get("nbformat_minor", 0)), + nbformat=int(meta.get("nbformat", NBFORMAT_MAJOR_VERSION)), + nbformat_minor=int(meta.get("nbformat_minor", NBFORMAT_MINOR_VERSION)), ) def set(self, value: Dict) -> None: diff --git a/pyproject.toml b/pyproject.toml index 7923d5c..fa89f80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,7 @@ test = [ "pytest", "pytest-asyncio", "websockets >=10.0", - "ypy-websocket >=0.8.3,<0.9.0", + "ypy-websocket >=0.8.3,<0.13.0", ] docs = [ "sphinx", From d56f45868ea7fc2a03c3af7186cb91d5b70cbf3f Mon Sep 17 00:00:00 2001 From: Carlos Herrero <26092748+hbcarlos@users.noreply.github.com> Date: Fri, 6 Oct 2023 11:45:39 +0200 Subject: [PATCH 2/3] Migrate tests to ypy-websockets 13 --- tests/conftest.py | 8 ++++++-- tests/test_ypy_yjs.py | 14 +++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ed1740f..68c857c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -32,9 +32,13 @@ async def yws_server(request): kwargs = request.param except Exception: kwargs = {} + websocket_server = WebsocketServer(**kwargs) - async with serve(websocket_server.serve, "localhost", 1234): - yield websocket_server + try: + async with websocket_server, serve(websocket_server.serve, "localhost", 1234): + yield websocket_server + except Exception: + pass @pytest.fixture diff --git a/tests/test_ypy_yjs.py b/tests/test_ypy_yjs.py index 5ba157b..0164ae1 100644 --- a/tests/test_ypy_yjs.py +++ b/tests/test_ypy_yjs.py @@ -53,13 +53,13 @@ def source(self): async def test_ypy_yjs_0(yws_server, yjs_client): ydoc = Y.YDoc() ynotebook = YNotebook(ydoc) - websocket = await connect("ws://localhost:1234/my-roomname") - WebsocketProvider(ydoc, websocket) - nb = stringify_source(json.loads((files_dir / "nb0.ipynb").read_text())) - ynotebook.source = nb - ytest = YTest(ydoc, 3.0) - await ytest.change() - assert ytest.source == nb + + async with connect("ws://localhost:1234/my-roomname") as websocket, WebsocketProvider(ydoc, websocket): + nb = stringify_source(json.loads((files_dir / "nb0.ipynb").read_text())) + ynotebook.source = nb + ytest = YTest(ydoc, 3.0) + await ytest.change() + assert ytest.source == nb def test_plotly_renderer(): From fe2964c9579a27d2ebc74de7d8b3262d45784141 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:47:23 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/conftest.py | 2 +- tests/test_ypy_yjs.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 68c857c..7d56267 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -32,7 +32,7 @@ async def yws_server(request): kwargs = request.param except Exception: kwargs = {} - + websocket_server = WebsocketServer(**kwargs) try: async with websocket_server, serve(websocket_server.serve, "localhost", 1234): diff --git a/tests/test_ypy_yjs.py b/tests/test_ypy_yjs.py index 0164ae1..744ae16 100644 --- a/tests/test_ypy_yjs.py +++ b/tests/test_ypy_yjs.py @@ -54,7 +54,9 @@ async def test_ypy_yjs_0(yws_server, yjs_client): ydoc = Y.YDoc() ynotebook = YNotebook(ydoc) - async with connect("ws://localhost:1234/my-roomname") as websocket, WebsocketProvider(ydoc, websocket): + async with connect("ws://localhost:1234/my-roomname") as websocket, WebsocketProvider( + ydoc, websocket + ): nb = stringify_source(json.loads((files_dir / "nb0.ipynb").read_text())) ynotebook.source = nb ytest = YTest(ydoc, 3.0)