Skip to content

Commit 3e26f0a

Browse files
committed
Update tests to expect specific events
1 parent 1600a20 commit 3e26f0a

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/test_ynotebook.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Distributed under the terms of the Modified BSD License.
33

44

5-
from pycrdt import Map, MapEvent
5+
from pycrdt import ArrayEvent, Map, MapEvent, TextEvent
66
from pytest import mark
77

88
from jupyter_ydoc import YNotebook
@@ -119,17 +119,17 @@ def record_changes(topic, event):
119119

120120

121121
@mark.parametrize(
122-
"modifications",
122+
"modifications, expected_events",
123123
[
124124
# modifications of single attributes
125-
[["source", "'b'"]],
126-
[["outputs", []]],
127-
[["execution_count", 2]],
125+
([["source", "'b'"]], {TextEvent}),
126+
([["outputs", []]], {ArrayEvent}),
127+
([["execution_count", 2]], {MapEvent}),
128128
# multi-attribute modifications
129-
[["source", "10"], ["execution_count", 10]],
129+
([["source", "10"], ["execution_count", 10]], {TextEvent, MapEvent}),
130130
],
131131
)
132-
def test_modify_single_cell(modifications):
132+
def test_modify_single_cell(modifications, expected_events):
133133
nb = YNotebook()
134134
nb.set(
135135
{
@@ -164,7 +164,9 @@ def record_changes(topic, event):
164164

165165
for modification in modifications:
166166
key, new_value = modification
167-
assert nb.ycells[0][key] == new_value
167+
after = nb.ycells[0][key]
168+
after_py = after.to_py() if hasattr(after, "to_py") else after
169+
assert after_py == new_value
168170

169171
# there should be only one change
170172
assert len(changes) == 1
@@ -173,6 +175,5 @@ def record_changes(topic, event):
173175
assert len(cell_events) == 1
174176
# but it should be a change to cell data, not a change to the cell list
175177
events = cell_events[0]
176-
# (it's neseted for some reason)
177-
assert len(events) == 1
178-
assert isinstance(events[0], MapEvent)
178+
assert len(events) == len(expected_events)
179+
assert {type(e) for e in events} == expected_events

0 commit comments

Comments
 (0)