Skip to content

Commit 4f3fdfd

Browse files
krassowskiasteppke
andauthored
Fix use of traitlets to configure YStore class (#322)
* Fix use of traitlets to configure YStore class * Add test case, apply fix in the fixture too Co-authored-by: asteppke <[email protected]> --------- Co-authored-by: asteppke <[email protected]>
1 parent 86ef807 commit 4f3fdfd

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

projects/jupyter-server-ydoc/jupyter_server_ydoc/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6+
from functools import partial
67
from typing import Literal
78

89
from jupyter_server.extension.application import ExtensionApp
@@ -96,13 +97,12 @@ def initialize_handlers(self):
9697
page_config.setdefault("serverSideExecution", self.server_side_execution)
9798

9899
# Set configurable parameters to YStore class
99-
for k, v in self.config.get(self.ystore_class.__name__, {}).items():
100-
setattr(self.ystore_class, k, v)
100+
ystore_class = partial(self.ystore_class, config=self.config)
101101

102102
self.ywebsocket_server = JupyterWebsocketServer(
103103
rooms_ready=False,
104104
auto_clean_rooms=False,
105-
ystore_class=self.ystore_class,
105+
ystore_class=ystore_class,
106106
# Log exceptions, because we don't want the websocket server
107107
# to _ever_ crash permanently in a live jupyter_server.
108108
exception_handler=exception_logger,
@@ -125,7 +125,7 @@ def initialize_handlers(self):
125125
"document_cleanup_delay": self.document_cleanup_delay,
126126
"document_save_delay": self.document_save_delay,
127127
"file_loaders": self.file_loaders,
128-
"ystore_class": self.ystore_class,
128+
"ystore_class": ystore_class,
129129
"ywebsocket_server": self.ywebsocket_server,
130130
},
131131
),

tests/conftest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,9 @@ async def _inner(format: str, type: str, path: str) -> None:
169169
return _inner
170170

171171

172-
@pytest.fixture
173-
def rtc_create_SQLite_store(jp_serverapp):
174-
for k, v in jp_serverapp.config.get("SQLiteYStore").items():
175-
setattr(SQLiteYStore, k, v)
176-
172+
def rtc_create_SQLite_store_factory(jp_serverapp):
177173
async def _inner(type: str, path: str, content: str) -> DocumentRoom:
178-
db = SQLiteYStore(path=f"{type}:{path}")
174+
db = SQLiteYStore(path=f"{type}:{path}", config=jp_serverapp.config)
179175
task = create_task(db.start())
180176
await db.started.wait()
181177

@@ -192,6 +188,11 @@ async def _inner(type: str, path: str, content: str) -> DocumentRoom:
192188
return _inner
193189

194190

191+
@pytest.fixture
192+
def rtc_create_SQLite_store(jp_serverapp):
193+
return rtc_create_SQLite_store_factory(jp_serverapp)
194+
195+
195196
@pytest.fixture
196197
def rtc_create_mock_document_room():
197198
def _inner(

tests/test_app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pytest
77
from jupyter_server_ydoc.stores import SQLiteYStore, TempFileYStore
88

9+
from .conftest import rtc_create_SQLite_store_factory
10+
911

1012
def test_default_settings(jp_serverapp):
1113
settings = jp_serverapp.web_app.settings["jupyter_server_ydoc_config"]
@@ -62,6 +64,19 @@ def test_settings_should_change_ystore_class(jp_configurable_serverapp):
6264
assert settings["ystore_class"] == TempFileYStore
6365

6466

67+
async def test_document_ttl_from_settings(rtc_create_mock_document_room, jp_configurable_serverapp):
68+
argv = ["--SQLiteYStore.document_ttl=3600"]
69+
70+
app = jp_configurable_serverapp(argv=argv)
71+
72+
id = "test-id"
73+
content = "test_ttl"
74+
rtc_create_SQLite_store = rtc_create_SQLite_store_factory(app)
75+
store = await rtc_create_SQLite_store("file", id, content)
76+
77+
assert store.document_ttl == 3600
78+
79+
6580
@pytest.mark.parametrize("copy", [True, False])
6681
async def test_get_document_file(rtc_create_file, jp_serverapp, copy):
6782
path, content = await rtc_create_file("test.txt", "test", store=True)

0 commit comments

Comments
 (0)