Skip to content

Commit ba2271d

Browse files
committed
Add more tests
1 parent af869e7 commit ba2271d

File tree

13 files changed

+65
-33
lines changed

13 files changed

+65
-33
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
strategy:
3636
matrix:
3737
os: [ubuntu-latest, windows-latest, macos-latest]
38+
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
3839
defaults:
3940
run:
4041
shell: bash -l {0}
@@ -48,7 +49,7 @@ jobs:
4849
- name: Install dependencies
4950
run: |
5051
micromamba install pip nodejs=18
51-
pip install ".[test]"
52+
pip install . --group test
5253
- name: Build JavaScript assets
5354
working-directory: javascript
5455
run: |
@@ -76,5 +77,11 @@ jobs:
7677
yarn build:test
7778
yarn test:cov
7879
- name: Run Python tests
80+
if: ${{ !((matrix.python-version == '3.14') && (matrix.os == 'ubuntu-latest')) }}
7981
run: |
8082
python -m pytest -v
83+
- name: Run Python code coverage
84+
if: ${{ (matrix.python-version == '3.14') && (matrix.os == 'ubuntu-latest') }}
85+
run: |
86+
coverage run -m pytest -v
87+
coverage report --show-missing

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ Which is just a shortcut to:
3030

3131
```py
3232
from importlib.metadata import entry_points
33-
# for Python < 3.10, install importlib_metadata and do:
34-
# from importlib_metadata import entry_points
3533

3634
ydocs = {ep.name: ep.load() for ep in entry_points(group="jupyter_ydoc")}
3735
```

jupyter_ydoc/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4-
import sys
5-
64
from ._version import __version__ as __version__
75
from .yblob import YBlob as YBlob
86
from .yfile import YFile as YFile
97
from .ynotebook import YNotebook as YNotebook
108
from .yunicode import YUnicode as YUnicode
119

12-
# See compatibility note on `group` keyword in
13-
# https://docs.python.org/3/library/importlib.metadata.html#entry-points
14-
if sys.version_info < (3, 10):
15-
from importlib_metadata import entry_points
16-
else:
17-
from importlib.metadata import entry_points
10+
from importlib.metadata import entry_points
1811

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

jupyter_ydoc/yblob.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def set(self, value: bytes) -> None:
6464
:param value: The content of the document.
6565
:type value: bytes
6666
"""
67+
if self.get() == value:
68+
return
69+
6770
self._ysource["bytes"] = value
6871

6972
def observe(self, callback: Callable[[str, Any], None]) -> None:

jupyter_ydoc/yunicode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def set(self, value: str) -> None:
6767
# no-op if the values are already the same,
6868
# to avoid side-effects such as cursor jumping to the top
6969
return
70+
7071
with self._ydoc.transaction():
7172
# clear document
7273
self._ysource.clear()

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@ build-backend = "hatchling.build"
99
name = "jupyter-ydoc"
1010
dynamic = ["version"]
1111
description = "Document structures for collaborative editing using Ypy"
12-
requires-python = ">=3.8"
12+
requires-python = ">=3.10"
1313
keywords = ["jupyter", "pycrdt", "yjs"]
1414
dependencies = [
15-
"importlib_metadata >=3.6; python_version<'3.10'",
1615
"pycrdt >=0.10.1,<0.13.0",
1716
]
1817

1918
[[project.authors]]
2019
name = "Jupyter Development Team"
2120
2221

23-
[project.optional-dependencies]
22+
[dependency-groups]
2423
dev = [
2524
"click",
2625
"jupyter_releaser",
@@ -33,6 +32,7 @@ test = [
3332
"httpx-ws >=0.5.2",
3433
"hypercorn >=0.16.0",
3534
"pycrdt-websocket >=0.16.0,<0.17.0",
35+
"coverage >=7.12.0,<8",
3636
]
3737
docs = [
3838
"sphinx",

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ def yjs_client(request):
6363
p.terminate()
6464
try:
6565
p.wait(timeout=10)
66-
except Exception:
66+
except Exception: # pragma: nocover
6767
p.kill()

tests/test_pycrdt_yjs.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66

77
import pytest
8-
from anyio import Event, create_task_group, move_on_after
8+
from anyio import Event, create_task_group, fail_after, move_on_after, sleep
99
from httpx_ws import aconnect_ws
1010
from pycrdt import Doc, Map, Provider
1111
from utils import Websocket
@@ -90,17 +90,12 @@ async def test_ypy_yjs_1(yws_server, yjs_client):
9090
):
9191
output_text = ynotebook.ycells[0]["outputs"][0]["text"]
9292
assert output_text.to_py() == "Hello,"
93-
event = Event()
9493

95-
def callback(_event):
96-
event.set()
97-
98-
output_text.observe(callback)
99-
100-
with move_on_after(10):
101-
await event.wait()
102-
103-
assert output_text.to_py() == "Hello,", " World!"
94+
with fail_after(10):
95+
while True:
96+
await sleep(0.1)
97+
if output_text.to_py() == "Hello, World!":
98+
break
10499

105100

106101
def test_plotly_renderer():

tests/test_yblob.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
4+
from jupyter_ydoc import YBlob
5+
6+
7+
def test_set_no_op_if_unchanged():
8+
blob = YBlob()
9+
10+
assert blob.version == "2.0.0"
11+
12+
content0 = b"012"
13+
blob.set(content0)
14+
15+
changes = []
16+
17+
def record_changes(topic, event):
18+
changes.append((topic, event)) # pragma: nocover
19+
20+
blob.observe(record_changes)
21+
22+
content1 = blob.get()
23+
assert content0 == content1
24+
25+
# Call set with identical content
26+
blob.set(content0)
27+
28+
# No changes should be observed at all
29+
assert changes == []

tests/test_ynotebook.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ def __eq__(self, other):
2626

2727
def test_set_preserves_cells_when_unchanged():
2828
nb = YNotebook()
29+
30+
assert nb.version == "2.0.0"
31+
2932
nb.set({"cells": [make_code_cell("print('a')\n"), make_code_cell("print('b')\n")]})
3033

3134
changes = []
3235

3336
def record_changes(topic, event):
34-
changes.append((topic, event))
37+
changes.append((topic, event)) # pragma: nocover
3538

3639
nb.observe(record_changes)
3740

0 commit comments

Comments
 (0)