Skip to content

Commit 3e49c8e

Browse files
author
Alan Fleming
committed
Fix tests and lock file.
1 parent 077d950 commit 3e49c8e

File tree

4 files changed

+152
-56
lines changed

4 files changed

+152
-56
lines changed

python/ipywidgets/ipywidgets/widgets/tests/test_send_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class SimpleWidget(Widget):
1717
c = List(Bool()).tag(sync=True)
1818

1919

20-
def test_empty_send_state(dummy_comm_fixture):
20+
def test_empty_send_state():
2121
w = SimpleWidget()
2222
w.send_state([])
2323
assert w.comm.messages == []
2424

2525

26-
def test_empty_hold_sync(dummy_comm_fixture):
26+
def test_empty_hold_sync():
2727
w = SimpleWidget()
2828
with w.hold_sync():
2929
pass

python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TruncateDataWidget(SimpleWidget):
8989
#
9090

9191

92-
def test_set_state_simple(echo, dummy_comm_fixture):
92+
def test_set_state_simple(echo):
9393
w = SimpleWidget()
9494
w.set_state(
9595
dict(
@@ -102,7 +102,7 @@ def test_set_state_simple(echo, dummy_comm_fixture):
102102
assert len(w.comm.messages) == (1 if echo else 0)
103103

104104

105-
def test_set_state_transformer(echo, dummy_comm_fixture):
105+
def test_set_state_transformer(echo):
106106
w = TransformerWidget()
107107
w.set_state(dict(d=[True, False, True]))
108108
# Since the deserialize step changes the state, this should send an update
@@ -137,7 +137,7 @@ def test_set_state_transformer(echo, dummy_comm_fixture):
137137
assert w.comm.messages == expected
138138

139139

140-
def test_set_state_data(echo, dummy_comm_fixture):
140+
def test_set_state_data(echo):
141141
w = DataWidget()
142142
data = memoryview(b"x" * 30)
143143
w.set_state(
@@ -149,7 +149,7 @@ def test_set_state_data(echo, dummy_comm_fixture):
149149
assert len(w.comm.messages) == (1 if echo else 0)
150150

151151

152-
def test_set_state_data_truncate(echo, dummy_comm_fixture):
152+
def test_set_state_data_truncate(echo):
153153
w = TruncateDataWidget()
154154
data = memoryview(b"x" * 30)
155155
w.set_state(
@@ -170,7 +170,7 @@ def test_set_state_data_truncate(echo, dummy_comm_fixture):
170170
assert buffers[0] == data[:20].tobytes()
171171

172172

173-
def test_set_state_numbers_int(echo, dummy_comm_fixture):
173+
def test_set_state_numbers_int(echo):
174174
# JS does not differentiate between float/int.
175175
# Instead, it formats exact floats as ints in JSON (1.0 -> '1').
176176

@@ -188,15 +188,15 @@ def test_set_state_numbers_int(echo, dummy_comm_fixture):
188188
assert len(w.comm.messages) == (1 if echo else 0)
189189

190190

191-
def test_set_state_numbers_float(echo, dummy_comm_fixture):
191+
def test_set_state_numbers_float(echo):
192192
w = NumberWidget()
193193
# Set floats to int-like floats
194194
w.set_state(dict(f=1.0, cf=2.0, ci=4.0))
195195
# Ensure one update message gets produced
196196
assert len(w.comm.messages) == (1 if echo else 0)
197197

198198

199-
def test_set_state_float_to_float(echo, dummy_comm_fixture):
199+
def test_set_state_float_to_float(echo):
200200
w = NumberWidget()
201201
# Set floats to float
202202
w.set_state(
@@ -209,7 +209,7 @@ def test_set_state_float_to_float(echo, dummy_comm_fixture):
209209
assert len(w.comm.messages) == (1 if echo else 0)
210210

211211

212-
def test_set_state_cint_to_float(echo, dummy_comm_fixture):
212+
def test_set_state_cint_to_float(echo):
213213
w = NumberWidget()
214214

215215
# Set CInt to float
@@ -236,15 +236,15 @@ def _x_test_set_state_int_to_int_like():
236236
assert len(w.comm.messages) == 0
237237

238238

239-
def test_set_state_int_to_float(echo, dummy_comm_fixture):
239+
def test_set_state_int_to_float(echo):
240240
w = NumberWidget()
241241

242242
# Set Int to float
243243
with pytest.raises(TraitError):
244244
w.set_state(dict(i=3.5))
245245

246246

247-
def test_property_lock(echo, dummy_comm_fixture):
247+
def test_property_lock(echo):
248248
# when this widget's value is set to 42, it sets itself to 2, and then back to 42 again (and then stops)
249249
class AnnoyingWidget(Widget):
250250
value = Float().tag(sync=True)
@@ -275,7 +275,7 @@ def _propagate_value(self, change):
275275
widget._send.assert_has_calls(calls)
276276

277277

278-
def test_hold_sync(echo, dummy_comm_fixture):
278+
def test_hold_sync(echo):
279279
# when this widget's value is set to 42, it sets the value to 2, and also sets a different trait value
280280
class AnnoyingWidget(Widget):
281281
value = Float().tag(sync=True)
@@ -310,7 +310,7 @@ def _propagate_value(self, change):
310310
widget._send.assert_has_calls(calls)
311311

312312

313-
def test_echo(dummy_comm_fixture):
313+
def test_echo():
314314
# we always echo values back to the frontend
315315
class ValueWidget(Widget):
316316
value = Float().tag(sync=True)
@@ -331,7 +331,7 @@ class ValueWidget(Widget):
331331
widget._send.assert_has_calls(calls)
332332

333333

334-
def test_echo_single(dummy_comm_fixture):
334+
def test_echo_single():
335335
# we always echo multiple changes back in 1 update
336336
class ValueWidget(Widget):
337337
value = Float().tag(sync=True)
@@ -373,7 +373,7 @@ def _square(self, change):
373373
widget._send.assert_has_calls(calls)
374374

375375

376-
def test_no_echo(dummy_comm_fixture):
376+
def test_no_echo():
377377
# in cases where values coming from the frontend are 'heavy', we might want to opt out
378378
class ValueWidget(Widget):
379379
value = Float().tag(sync=True, echo_update=False)

python/ipywidgets/ipywidgets/widgets/tests/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
# The new comm package is not available in our Python 3.7 CI (older ipykernel version)
1010
try:
1111
import comm
12+
1213
NEW_COMM_PACKAGE = True
1314
except ImportError:
1415
NEW_COMM_PACKAGE = False
1516

1617
import ipykernel.comm
1718
import pytest
1819

19-
class DummyComm():
20-
comm_id = 'a-b-c-d'
21-
kernel = 'Truthy'
20+
21+
class DummyComm:
22+
comm_id = "a-b-c-d"
23+
kernel = "Truthy"
2224

2325
def __init__(self, *args, **kwargs):
2426
super().__init__()
@@ -59,6 +61,7 @@ def dummy_get_comm_manager(**kwargs):
5961
orig_create_comm = comm.create_comm
6062
orig_get_comm_manager = comm.get_comm_manager
6163

64+
6265
def setup_test_comm():
6366
if NEW_COMM_PACKAGE:
6467
comm.create_comm = dummy_create_comm
@@ -68,11 +71,14 @@ def setup_test_comm():
6871
ipykernel.comm.Comm = DummyComm
6972
Widget.comm.klass = DummyComm
7073
ipywidgets.widgets.widget.Comm = DummyComm
71-
_widget_attrs['_repr_mimebundle_'] = Widget._repr_mimebundle_
74+
_widget_attrs["_repr_mimebundle_"] = Widget._repr_mimebundle_
75+
7276
def raise_not_implemented(*args, **kwargs):
7377
raise NotImplementedError()
78+
7479
Widget._repr_mimebundle_ = raise_not_implemented
7580

81+
7682
def teardown_test_comm():
7783
if NEW_COMM_PACKAGE:
7884
comm.create_comm = orig_create_comm
@@ -89,12 +95,14 @@ def teardown_test_comm():
8995
setattr(Widget, attr, value)
9096
_widget_attrs.clear()
9197

98+
9299
@pytest.fixture(autouse=True)
93100
def setup():
94101
setup_test_comm()
95102
yield
96103
teardown_test_comm()
97104

105+
98106
def call_method(method, *args, **kwargs):
99107
method(*args, **kwargs)
100108

@@ -105,4 +113,4 @@ def dummy_comm_fixture():
105113
try:
106114
yield
107115
finally:
108-
teardown()
116+
teardown_test_comm()

0 commit comments

Comments
 (0)