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", diff --git a/tests/conftest.py b/tests/conftest.py index ed1740f..7d56267 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..744ae16 100644 --- a/tests/test_ypy_yjs.py +++ b/tests/test_ypy_yjs.py @@ -53,13 +53,15 @@ 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():