diff --git a/projects/jupyter-server-ydoc/jupyter_server_ydoc/pytest_plugin.py b/projects/jupyter-server-ydoc/jupyter_server_ydoc/pytest_plugin.py index afd2f6c3..8bb8479e 100644 --- a/projects/jupyter-server-ydoc/jupyter_server_ydoc/pytest_plugin.py +++ b/projects/jupyter-server-ydoc/jupyter_server_ydoc/pytest_plugin.py @@ -9,14 +9,19 @@ import nbformat import pytest +from httpx_ws import aconnect_ws from jupyter_server_ydoc.loaders import FileLoader from jupyter_server_ydoc.rooms import DocumentRoom from jupyter_server_ydoc.stores import SQLiteYStore from jupyter_ydoc import YNotebook, YUnicode from pycrdt_websocket import WebsocketProvider -from httpx_ws import aconnect_ws -from .test_utils import FakeContentsManager, FakeEventLogger, FakeFileIDManager, Websocket +from .test_utils import ( + FakeContentsManager, + FakeEventLogger, + FakeFileIDManager, + Websocket, +) @pytest.fixture @@ -139,9 +144,12 @@ async def _inner(format: str, type: str, path: str) -> Any: resp = await rtc_fetch_session(format, type, path) data = json.loads(resp.body.decode("utf-8")) room_name = f"{data['format']}:{data['type']}:{data['fileId']}" - return aconnect_ws( - f"http://127.0.0.1:{jp_http_port}{jp_base_url}api/collaboration/room/{room_name}?sessionId={data['sessionId']}" - ), room_name + return ( + aconnect_ws( + f"http://127.0.0.1:{jp_http_port}{jp_base_url}api/collaboration/room/{room_name}?sessionId={data['sessionId']}" + ), + room_name, + ) return _inner diff --git a/projects/jupyter-server-ydoc/jupyter_server_ydoc/test_utils.py b/projects/jupyter-server-ydoc/jupyter_server_ydoc/test_utils.py index fc0263bc..8ced6ea0 100644 --- a/projects/jupyter-server-ydoc/jupyter_server_ydoc/test_utils.py +++ b/projects/jupyter-server-ydoc/jupyter_server_ydoc/test_utils.py @@ -6,8 +6,8 @@ from datetime import datetime from typing import Any -from jupyter_server import _tz as tz from anyio import Lock +from jupyter_server import _tz as tz class FakeFileIDManager: diff --git a/tests/test_documents.py b/tests/test_documents.py index 4b1428dc..9065a1aa 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -11,8 +11,8 @@ import pytest from anyio import create_task_group, sleep -from pycrdt_websocket import WebsocketProvider from jupyter_server_ydoc.test_utils import Websocket +from pycrdt_websocket import WebsocketProvider jupyter_ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")} diff --git a/tests/test_handlers.py b/tests/test_handlers.py index c8708c05..7cb55e0b 100644 --- a/tests/test_handlers.py +++ b/tests/test_handlers.py @@ -79,9 +79,7 @@ def _on_document_change(target: str, e: Any) -> None: doc.observe(_on_document_change) websocket, room_name = await rtc_connect_doc_client("text", "file", path) - async with websocket as ws, WebsocketProvider( - doc.ydoc, Websocket(ws, room_name) - ): + async with websocket as ws, WebsocketProvider(doc.ydoc, Websocket(ws, room_name)): await event.wait() await sleep(0.1) @@ -117,9 +115,7 @@ async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None: ) websocket, room_name = await rtc_connect_doc_client("text", "file", path) - async with websocket as ws, WebsocketProvider( - doc.ydoc, Websocket(ws, room_name) - ): + async with websocket as ws, WebsocketProvider(doc.ydoc, Websocket(ws, room_name)): await event.wait() await sleep(0.1) @@ -151,9 +147,7 @@ def _on_document_change(target: str, e: Any) -> None: doc.observe(_on_document_change) websocket, room_name = await rtc_connect_doc_client("text", "file", path) - async with websocket as ws, WebsocketProvider( - doc.ydoc, Websocket(ws, room_name) - ): + async with websocket as ws, WebsocketProvider(doc.ydoc, Websocket(ws, room_name)): await event.wait() await sleep(0.1) @@ -178,9 +172,7 @@ async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None: try: websocket, room_name = await rtc_connect_doc_client("text2", "file2", path2) - async with websocket as ws, WebsocketProvider( - doc.ydoc, Websocket(ws, room_name) - ): + async with websocket as ws, WebsocketProvider(doc.ydoc, Websocket(ws, room_name)): await event.wait() await sleep(0.1) except Exception: @@ -188,9 +180,7 @@ async def my_listener(logger: EventLogger, schema_id: str, data: dict) -> None: try: websocket, room_name = await rtc_connect_doc_client("text2", "file2", path2) - async with websocket as ws, WebsocketProvider( - doc.ydoc, Websocket(ws, room_name) - ): + async with websocket as ws, WebsocketProvider(doc.ydoc, Websocket(ws, room_name)): await event.wait() await sleep(0.1) except Exception: