Skip to content

Commit

Permalink
Fix tests that need dummy comm & update yarn.lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Fleming committed Jun 9, 2024
1 parent 75da2f9 commit 0c1dafe
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 52 deletions.
2 changes: 1 addition & 1 deletion packages/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test:unit:ie": "npm run test:unit:default -- --browsers=IE"
},
"dependencies": {
"@jupyter-widgets/base": "^6.0.7",
"@jupyter-widgets/base": "^6.0.8",
"@lumino/algorithm": "^1.9.2 || ^2.0.1",
"@lumino/domutils": "^1.8.1 || ^2.1",
"@lumino/messaging": "^1.10.1 || ^2.0.1",
Expand Down
8 changes: 5 additions & 3 deletions python/ipywidgets/ipywidgets/widgets/tests/test_send_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

from traitlets import Bool, Tuple, List

from .utils import setup, teardown, DummyComm

from .utils import dummy_comm_fixture

from ..widget import Widget

from ..._version import __control_protocol_version__


# A widget with simple traits
class SimpleWidget(Widget):
a = Bool().tag(sync=True)
Expand All @@ -18,13 +20,13 @@ class SimpleWidget(Widget):
c = List(Bool()).tag(sync=True)


def test_empty_send_state():
def test_empty_send_state(dummy_comm_fixture):
w = SimpleWidget()
w.send_state([])
assert w.comm.messages == []


def test_empty_hold_sync():
def test_empty_hold_sync(dummy_comm_fixture):
w = SimpleWidget()
with w.hold_sync():
pass
Expand Down
30 changes: 15 additions & 15 deletions python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from traitlets import Bool, Tuple, List, Instance, CFloat, CInt, Float, Int, TraitError, observe

from .utils import setup, teardown
from .utils import dummy_comm_fixture # noqa: F401

import ipywidgets
from ipywidgets import Widget
Expand Down Expand Up @@ -81,7 +81,7 @@ class TruncateDataWidget(SimpleWidget):
# Actual tests:
#

def test_set_state_simple(echo):
def test_set_state_simple(echo, dummy_comm_fixture):
w = SimpleWidget()
w.set_state(dict(
a=True,
Expand All @@ -92,7 +92,7 @@ def test_set_state_simple(echo):
assert len(w.comm.messages) == (1 if echo else 0)


def test_set_state_transformer(echo):
def test_set_state_transformer(echo, dummy_comm_fixture):
w = TransformerWidget()
w.set_state(dict(
d=[True, False, True]
Expand All @@ -119,7 +119,7 @@ def test_set_state_transformer(echo):
assert w.comm.messages == expected


def test_set_state_data(echo):
def test_set_state_data(echo, dummy_comm_fixture):
w = DataWidget()
data = memoryview(b'x'*30)
w.set_state(dict(
Expand All @@ -129,7 +129,7 @@ def test_set_state_data(echo):
assert len(w.comm.messages) == (1 if echo else 0)


def test_set_state_data_truncate(echo):
def test_set_state_data_truncate(echo, dummy_comm_fixture):
w = TruncateDataWidget()
data = memoryview(b'x'*30)
w.set_state(dict(
Expand All @@ -153,7 +153,7 @@ def test_set_state_data_truncate(echo):
assert buffers[0] == data[:20].tobytes()


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

Expand All @@ -169,7 +169,7 @@ def test_set_state_numbers_int(echo):
assert len(w.comm.messages) == (1 if echo else 0)


def test_set_state_numbers_float(echo):
def test_set_state_numbers_float(echo, dummy_comm_fixture):
w = NumberWidget()
# Set floats to int-like floats
w.set_state(dict(
Expand All @@ -181,7 +181,7 @@ def test_set_state_numbers_float(echo):
assert len(w.comm.messages) == (1 if echo else 0)


def test_set_state_float_to_float(echo):
def test_set_state_float_to_float(echo, dummy_comm_fixture):
w = NumberWidget()
# Set floats to float
w.set_state(dict(
Expand All @@ -192,7 +192,7 @@ def test_set_state_float_to_float(echo):
assert len(w.comm.messages) == (1 if echo else 0)


def test_set_state_cint_to_float(echo):
def test_set_state_cint_to_float(echo, dummy_comm_fixture):
w = NumberWidget()

# Set CInt to float
Expand Down Expand Up @@ -223,7 +223,7 @@ def _x_test_set_state_int_to_int_like():
assert len(w.comm.messages) == 0


def test_set_state_int_to_float(echo):
def test_set_state_int_to_float(echo, dummy_comm_fixture):
w = NumberWidget()

# Set Int to float
Expand All @@ -232,7 +232,7 @@ def test_set_state_int_to_float(echo):
i = 3.5
))

def test_property_lock(echo):
def test_property_lock(echo, dummy_comm_fixture):
# when this widget's value is set to 42, it sets itself to 2, and then back to 42 again (and then stops)
class AnnoyingWidget(Widget):
value = Float().tag(sync=True)
Expand Down Expand Up @@ -262,7 +262,7 @@ def _propagate_value(self, change):
calls = []
widget._send.assert_has_calls(calls)

def test_hold_sync(echo):
def test_hold_sync(echo, dummy_comm_fixture):
# when this widget's value is set to 42, it sets the value to 2, and also sets a different trait value
class AnnoyingWidget(Widget):
value = Float().tag(sync=True)
Expand Down Expand Up @@ -298,7 +298,7 @@ def _propagate_value(self, change):



def test_echo():
def test_echo(dummy_comm_fixture):
# we always echo values back to the frontend
class ValueWidget(Widget):
value = Float().tag(sync=True)
Expand All @@ -319,7 +319,7 @@ class ValueWidget(Widget):
widget._send.assert_has_calls(calls)


def test_echo_single():
def test_echo_single(dummy_comm_fixture):
# we always echo multiple changes back in 1 update
class ValueWidget(Widget):
value = Float().tag(sync=True)
Expand Down Expand Up @@ -359,7 +359,7 @@ def _square(self, change):
widget._send.assert_has_calls(calls)


def test_no_echo(echo):
def test_no_echo(dummy_comm_fixture):
# in cases where values coming from the frontend are 'heavy', we might want to opt out
class ValueWidget(Widget):
value = Float().tag(sync=True, echo_update=False)
Expand Down
11 changes: 11 additions & 0 deletions python/ipywidgets/ipywidgets/widgets/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import pytest

from ipywidgets import Widget
import ipywidgets.widgets.widget

Expand Down Expand Up @@ -95,3 +97,12 @@ def teardown():

def call_method(method, *args, **kwargs):
method(*args, **kwargs)


@pytest.fixture
def dummy_comm_fixture():
setup()
try:
yield
finally:
teardown()
66 changes: 33 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,11 @@ __metadata:
languageName: node
linkType: hard

"@jupyter-widgets/base-manager@^1.0.8, @jupyter-widgets/base-manager@workspace:packages/base-manager":
"@jupyter-widgets/base-manager@^1.0.9, @jupyter-widgets/base-manager@workspace:packages/base-manager":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/base-manager@workspace:packages/base-manager"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base": ^6.0.8
"@jupyterlab/services": ^6.0.0 || ^7.0.0
"@lumino/coreutils": ^1.11.1 || ^2
"@types/base64-js": ^1.2.5
Expand Down Expand Up @@ -770,7 +770,7 @@ __metadata:
languageName: unknown
linkType: soft

"@jupyter-widgets/base@^6.0.7, @jupyter-widgets/base@workspace:packages/base":
"@jupyter-widgets/base@^6.0.8, @jupyter-widgets/base@workspace:packages/base":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/base@workspace:packages/base"
dependencies:
Expand Down Expand Up @@ -812,11 +812,11 @@ __metadata:
languageName: unknown
linkType: soft

"@jupyter-widgets/controls@^5.0.8, @jupyter-widgets/controls@workspace:packages/controls":
"@jupyter-widgets/controls@^5.0.9, @jupyter-widgets/controls@workspace:packages/controls":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/controls@workspace:packages/controls"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base": ^6.0.8
"@jupyterlab/services": ^6.0.0 || ^7.0.0
"@lumino/algorithm": ^1.9.2 || ^2.0.1
"@lumino/domutils": ^1.8.1 || ^2.1
Expand Down Expand Up @@ -866,9 +866,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/example-web1@workspace:examples/web1"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base-manager": ^1.0.8
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/base-manager": ^1.0.9
"@jupyter-widgets/controls": ^5.0.9
chai: ^4.0.0
css-loader: ^6.5.1
karma: ^6.3.3
Expand All @@ -887,9 +887,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/example-web2@workspace:examples/web2"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base-manager": ^1.0.8
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/base-manager": ^1.0.9
"@jupyter-widgets/controls": ^5.0.9
codemirror: ^5.48.0
css-loader: ^6.5.1
font-awesome: ^4.7.0
Expand All @@ -902,9 +902,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/example-web3@workspace:examples/web3"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/html-manager": ^1.0.10
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/controls": ^5.0.9
"@jupyter-widgets/html-manager": ^1.0.11
"@jupyterlab/services": ^6.0.0 || ^7.0.0
"@types/codemirror": ^5.60.0
"@types/node": ^17.0.2
Expand All @@ -924,24 +924,24 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/example-web4@workspace:examples/web4"
dependencies:
"@jupyter-widgets/html-manager": ^1.0.10
"@jupyter-widgets/html-manager": ^1.0.11
css-loader: ^6.5.1
font-awesome: ^4.7.0
style-loader: ^3.3.1
webpack: ^5.65.0
languageName: unknown
linkType: soft

"@jupyter-widgets/html-manager@^1.0.10, @jupyter-widgets/html-manager@workspace:packages/html-manager":
"@jupyter-widgets/html-manager@^1.0.11, @jupyter-widgets/html-manager@workspace:packages/html-manager":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/html-manager@workspace:packages/html-manager"
dependencies:
"@fortawesome/fontawesome-free": ^5.12.0
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base-manager": ^1.0.8
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/output": ^6.0.7
"@jupyter-widgets/schema": ^0.5.4
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/base-manager": ^1.0.9
"@jupyter-widgets/controls": ^5.0.9
"@jupyter-widgets/output": ^6.0.8
"@jupyter-widgets/schema": ^0.5.5
"@jupyterlab/outputarea": ^3.0.0 || ^4.0.0
"@jupyterlab/rendermime": ^3.0.0 || ^4.0.0
"@jupyterlab/rendermime-interfaces": ^3.0.0 || ^4.0.0
Expand Down Expand Up @@ -978,10 +978,10 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/jupyterlab-manager@workspace:python/jupyterlab_widgets"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base-manager": ^1.0.8
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/output": ^6.0.7
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/base-manager": ^1.0.9
"@jupyter-widgets/controls": ^5.0.9
"@jupyter-widgets/output": ^6.0.8
"@jupyterlab/application": ^3.0.0 || ^4.0.0
"@jupyterlab/apputils": ^3.0.0 || ^4.0.0
"@jupyterlab/builder": ^3.0.0 || ^4.0.0
Expand Down Expand Up @@ -1034,11 +1034,11 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyter-widgets/notebook-manager@workspace:python/widgetsnbextension"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base-manager": ^1.0.8
"@jupyter-widgets/controls": ^5.0.8
"@jupyter-widgets/html-manager": ^1.0.10
"@jupyter-widgets/output": ^6.0.7
"@jupyter-widgets/base": ^6.0.8
"@jupyter-widgets/base-manager": ^1.0.9
"@jupyter-widgets/controls": ^5.0.9
"@jupyter-widgets/html-manager": ^1.0.11
"@jupyter-widgets/output": ^6.0.8
"@jupyterlab/services": ^6.0.0 || ^7.0.0
"@lumino/messaging": ^1.10.1 || ^2.0.1
"@lumino/widgets": ^1.30.0 || ^2.1
Expand All @@ -1052,17 +1052,17 @@ __metadata:
languageName: unknown
linkType: soft

"@jupyter-widgets/output@^6.0.7, @jupyter-widgets/output@workspace:packages/output":
"@jupyter-widgets/output@^6.0.8, @jupyter-widgets/output@workspace:packages/output":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/output@workspace:packages/output"
dependencies:
"@jupyter-widgets/base": ^6.0.7
"@jupyter-widgets/base": ^6.0.8
rimraf: ^3.0.2
typescript: ~4.9.4
languageName: unknown
linkType: soft

"@jupyter-widgets/schema@^0.5.4, @jupyter-widgets/schema@workspace:packages/schema":
"@jupyter-widgets/schema@^0.5.5, @jupyter-widgets/schema@workspace:packages/schema":
version: 0.0.0-use.local
resolution: "@jupyter-widgets/schema@workspace:packages/schema"
languageName: unknown
Expand Down

0 comments on commit 0c1dafe

Please sign in to comment.