1313from jupyter_server_fileid .manager import ArbitraryFileIdManager , BaseFileIdManager
1414from jupyter_ydoc import YUnicode
1515
16+
17+ @pytest .fixture
18+ def jp_contents_manager (tmp_path ):
19+ """A copy of the fixture from jupyter_server, to avoid duplicate runs
20+ due to parameters in the original fixture"""
21+ return AsyncFileContentsManager (root_dir = str (tmp_path ), use_atomic_writing = False )
22+
23+
1624@pytest .fixture
1725def mock_plaintext_file (tmp_path ):
1826 # Copy mock file to /tmp
@@ -26,6 +34,9 @@ def mock_plaintext_file(tmp_path):
2634 # Cleanup
2735 os .remove (target_path )
2836
37+ def noop ():
38+ pass
39+
2940@pytest_asyncio .fixture (loop_scope = "module" )
3041async def plaintext_file_api (mock_plaintext_file : str , jp_contents_manager : AsyncFileContentsManager ):
3142 """
@@ -38,7 +49,8 @@ async def plaintext_file_api(mock_plaintext_file: str, jp_contents_manager: Asyn
3849 contents_manager = jp_contents_manager
3950 loop = asyncio .get_running_loop ()
4051
41- file_id = fileid_manager .index (mock_plaintext_file )
52+ filename = os .path .basename (mock_plaintext_file )
53+ file_id = fileid_manager .index (filename )
4254 room_id = f"text:file:{ file_id } "
4355 ydoc = pycrdt .Doc ()
4456 awareness = pycrdt .Awareness (ydoc = ydoc )
@@ -50,6 +62,9 @@ async def plaintext_file_api(mock_plaintext_file: str, jp_contents_manager: Asyn
5062 fileid_manager = fileid_manager ,
5163 log = log ,
5264 loop = loop ,
65+ on_inband_deletion = noop ,
66+ on_outofband_change = noop ,
67+ on_outofband_move = noop
5368 )
5469 return yroom_file_api
5570
@@ -59,7 +74,7 @@ async def test_load_plaintext_file(plaintext_file_api: Awaitable[YRoomFileAPI],
5974 file_api = await plaintext_file_api
6075 jupyter_ydoc = file_api .jupyter_ydoc
6176 file_api .load_ydoc_content ()
62- await file_api .ydoc_content_loaded
77+ await file_api .ydoc_content_loaded . wait ()
6378
6479 # Assert that `get_jupyter_ydoc()` returns a `jupyter_ydoc.YUnicode` object
6580 # for plaintext files
@@ -69,4 +84,7 @@ async def test_load_plaintext_file(plaintext_file_api: Awaitable[YRoomFileAPI],
6984 with open (mock_plaintext_file ) as f :
7085 content = f .read ()
7186 assert jupyter_ydoc .source == content
87+
88+ # stop file file api to avoid coroutine warnings
89+ file_api .stop ()
7290
0 commit comments