Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Nov 18, 2024
1 parent 3dc8db2 commit 5c1ff55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
18 changes: 13 additions & 5 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")}

Expand Down
20 changes: 5 additions & 15 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -178,19 +172,15 @@ 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:
pass

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:
Expand Down

0 comments on commit 5c1ff55

Please sign in to comment.