Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for document dirty attribute #251

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ test = [
"jupyter_server_fileid[test]",
"pytest>=7.0",
"pytest-cov",
"websockets"
"websockets",
"importlib_metadata >=3.6; python_version<'3.10'",
Zsailer marked this conversation as resolved.
Show resolved Hide resolved
]
docs = [
"jupyterlab>=4.0.0",
Expand Down
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@


@pytest.fixture
def jp_server_config(jp_root_dir, jp_server_config):
def rtc_document_save_delay():
return 1


@pytest.fixture
def jp_server_config(jp_root_dir, jp_server_config, rtc_document_save_delay):
return {
"ServerApp": {
"jpserver_extensions": {"jupyter_collaboration": True, "jupyter_server_fileid": True},
Expand All @@ -37,6 +42,7 @@ def jp_server_config(jp_root_dir, jp_server_config):
"db_path": str(jp_root_dir.joinpath(".fid_test.db")),
"db_journal_mode": "OFF",
},
"YDocExtension": {"document_save_delay": rtc_document_save_delay},
}


Expand Down
39 changes: 39 additions & 0 deletions tests/test_documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import sys

if sys.version_info < (3, 10):
from importlib_metadata import entry_points
else:
from importlib.metadata import entry_points

import pytest
from anyio import sleep
from pycrdt_websocket import WebsocketProvider

jupyter_ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")}


@pytest.fixture
def rtc_document_save_delay():
return 0.5


async def test_dirty(
rtc_create_file,
rtc_connect_doc_client,
rtc_document_save_delay,
):
file_format = "text"
file_type = "file"
file_path = "dummy.txt"
await rtc_create_file(file_path)
jupyter_ydoc = jupyter_ydocs[file_type]()

async with await rtc_connect_doc_client(file_format, file_type, file_path) as ws:
async with WebsocketProvider(jupyter_ydoc.ydoc, ws):
for _ in range(2):
jupyter_ydoc.dirty = True
await sleep(rtc_document_save_delay * 1.5)
assert not jupyter_ydoc.dirty
Loading