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 notebook test for get_document, fix fixture when store=True #329

Merged
merged 5 commits into from
Jul 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ async def _inner(format: str, type: str, path: str) -> Any:
def rtc_add_doc_to_store(rtc_connect_doc_client):
event = Event()

def _on_document_change(target: str, e: Any) -> None:
if target == "source":
event.set()

async def _inner(format: str, type: str, path: str) -> None:
def _on_document_change(target: str, e: Any) -> None:
expected_target = "cells" if type == "notebook" else "source"
if target == expected_target:
event.set()

if type == "notebook":
doc = YNotebook()
else:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import nbformat
import pytest
from jupyter_server_ydoc.pytest_plugin import rtc_create_SQLite_store_factory
from jupyter_server_ydoc.stores import SQLiteYStore, TempFileYStore
Expand Down Expand Up @@ -87,6 +88,25 @@ async def test_get_document_file(rtc_create_file, jp_serverapp, copy):
await collaboration.stop_extension()


@pytest.mark.parametrize("copy", [True, False])
async def test_get_document_notebook(rtc_create_notebook, jp_serverapp, copy):
nb = nbformat.v4.new_notebook(
cells=[nbformat.v4.new_code_cell(source="1+1", execution_count=99)]
)
nb_content = nbformat.writes(nb, version=4)
path, _ = await rtc_create_notebook("test.ipynb", nb_content, store=True)
collaboration = jp_serverapp.web_app.settings["jupyter_server_ydoc"]
document = await collaboration.get_document(
path=path, content_type="notebook", file_format="json", copy=copy
)
doc = document.get()
assert len(doc["cells"]) == 1
cell = doc["cells"][0]
assert cell["source"] == "1+1"
assert cell["execution_count"] == 99
await collaboration.stop_extension()


async def test_get_document_file_copy_is_independent(
rtc_create_file, jp_serverapp, rtc_fetch_session
):
Expand Down
Loading