66
77import pytest
88from anyio import Event , create_task_group , move_on_after
9+ from httpx_ws import aconnect_ws
910from pycrdt import Doc , Map
1011from pycrdt_websocket import WebsocketProvider
11- from websockets import connect
12+ from utils import Websocket
1213
1314from jupyter_ydoc import YNotebook
1415from jupyter_ydoc .utils import cast_all
@@ -61,10 +62,12 @@ def source(self):
6162@pytest .mark .asyncio
6263@pytest .mark .parametrize ("yjs_client" , "0" , indirect = True )
6364async def test_ypy_yjs_0 (yws_server , yjs_client ):
65+ port , _ = yws_server
6466 ydoc = Doc ()
6567 ynotebook = YNotebook (ydoc )
66- async with connect ("ws://localhost:1234/my-roomname" ) as websocket , WebsocketProvider (
67- ydoc , websocket
68+ room_name = "my-roomname"
69+ async with aconnect_ws (f"http://localhost:{ port } /{ room_name } " ) as websocket , WebsocketProvider (
70+ ydoc , Websocket (websocket , room_name )
6871 ):
6972 nb = stringify_source (json .loads ((files_dir / "nb0.ipynb" ).read_text ()))
7073 ynotebook .source = nb
@@ -77,12 +80,14 @@ async def test_ypy_yjs_0(yws_server, yjs_client):
7780@pytest .mark .asyncio
7881@pytest .mark .parametrize ("yjs_client" , "1" , indirect = True )
7982async def test_ypy_yjs_1 (yws_server , yjs_client ):
83+ port , _ = yws_server
8084 ydoc = Doc ()
8185 ynotebook = YNotebook (ydoc )
8286 nb = stringify_source (json .loads ((files_dir / "nb1.ipynb" ).read_text ()))
8387 ynotebook .source = nb
84- async with connect ("ws://localhost:1234/my-roomname" ) as websocket , WebsocketProvider (
85- ydoc , websocket
88+ room_name = "my-roomname"
89+ async with aconnect_ws (f"http://localhost:{ port } /{ room_name } " ) as websocket , WebsocketProvider (
90+ ydoc , Websocket (websocket , room_name )
8691 ):
8792 output_text = ynotebook .ycells [0 ]["outputs" ][0 ]["text" ]
8893 assert output_text .to_py () == ["Hello," ]
0 commit comments