Skip to content

Commit 75631be

Browse files
davidbrochartandrii-i
authored andcommitted
Add test for document dirty attribute (jupyterlab#251)
* Add test for document dirty attribute * Add rtc_document_save_delay fixture
1 parent cabd087 commit 75631be

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ test = [
4949
"jupyter_server_fileid[test]",
5050
"pytest>=7.0",
5151
"pytest-cov",
52-
"websockets"
52+
"websockets",
53+
"importlib_metadata >=3.6; python_version<'3.10'",
5354
]
5455
docs = [
5556
"jupyterlab>=4.0.0",

tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424

2525

2626
@pytest.fixture
27-
def jp_server_config(jp_root_dir, jp_server_config):
27+
def rtc_document_save_delay():
28+
return 1
29+
30+
31+
@pytest.fixture
32+
def jp_server_config(jp_root_dir, jp_server_config, rtc_document_save_delay):
2833
return {
2934
"ServerApp": {
3035
"jpserver_extensions": {"jupyter_collaboration": True, "jupyter_server_fileid": True},
@@ -38,6 +43,7 @@ def jp_server_config(jp_root_dir, jp_server_config):
3843
"db_path": str(jp_root_dir.joinpath(".fid_test.db")),
3944
"db_journal_mode": "OFF",
4045
},
46+
"YDocExtension": {"document_save_delay": rtc_document_save_delay},
4147
}
4248

4349

tests/test_documents.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
import sys
5+
6+
if sys.version_info < (3, 10):
7+
from importlib_metadata import entry_points
8+
else:
9+
from importlib.metadata import entry_points
10+
11+
import pytest
12+
from anyio import sleep
13+
from pycrdt_websocket import WebsocketProvider
14+
15+
jupyter_ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")}
16+
17+
18+
@pytest.fixture
19+
def rtc_document_save_delay():
20+
return 0.5
21+
22+
23+
async def test_dirty(
24+
rtc_create_file,
25+
rtc_connect_doc_client,
26+
rtc_document_save_delay,
27+
):
28+
file_format = "text"
29+
file_type = "file"
30+
file_path = "dummy.txt"
31+
await rtc_create_file(file_path)
32+
jupyter_ydoc = jupyter_ydocs[file_type]()
33+
34+
async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws:
35+
async with WebsocketProvider(jupyter_ydoc.ydoc, ws):
36+
for _ in range(2):
37+
jupyter_ydoc.dirty = True
38+
await sleep(rtc_document_save_delay * 1.5)
39+
assert not jupyter_ydoc.dirty

0 commit comments

Comments
 (0)