Skip to content

Commit f703938

Browse files
authored
Fix fileapi tests (#108)
* Fixed file api tests. * Fixed output processor test * Updated python version * Fixes checklinks CI
1 parent 30e5c7b commit f703938

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
- name: Install Python
7272
uses: actions/setup-python@v5
7373
with:
74-
python-version: '3.9'
74+
python-version: '3.10'
7575
architecture: 'x64'
7676
- uses: actions/download-artifact@v4
7777
with:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# jupyter_server_documents
22

3-
[![Github Actions Status](https://github.com/jupyter-ai-contrib/jupyter_server_documents/workflows/Build/badge.svg)](https://github.com/jupyter-ai-contrib/jupyter_server_documents/actions/workflows/build.yml)
4-
53
A JupyterLab extension that provides RTC capabilities.
64

75
This extension is composed of a Python package named `jupyter_server_documents`

jupyter_server_documents/tests/test_output_processor.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import json
2+
import pytest
23
from pathlib import Path
34
from tempfile import TemporaryDirectory
45
from uuid import uuid4
56

67
from ..outputs import OutputProcessor, OutputsManager
78

8-
class TestOutputProcessor(OutputProcessor):
9+
class OutputProcessorForTest(OutputProcessor):
10+
"""Test subclass of OutputProcessor that overrides the settings property."""
11+
_test_settings = {}
912

10-
settings = {}
13+
@property
14+
def settings(self):
15+
"""Override the settings property to return a test dictionary."""
16+
return self._test_settings
17+
18+
@pytest.fixture
19+
def output_processor():
20+
"""Fixture that returns an instance of TestOutputProcessor."""
21+
return OutputProcessorForTest()
1122

1223
def create_incoming_message(cell_id):
1324
msg_id = str(uuid4())
@@ -17,9 +28,9 @@ def create_incoming_message(cell_id):
1728
msg = [json.dumps(item) for item in [header, parent_header, metadata]]
1829
return msg_id, msg
1930

20-
def test_instantiation():
31+
def test_instantiation(output_processor):
2132
"""Test instantiation of the output processor."""
22-
op = OutputProcessor()
33+
op = output_processor
2334
assert isinstance(op, OutputProcessor)
2435

2536
# TODO: Implement this

jupyter_server_documents/tests/test_yroom_file_api.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
from jupyter_server_fileid.manager import ArbitraryFileIdManager, BaseFileIdManager
1414
from 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
1725
def 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")
3041
async 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

Comments
 (0)