From 46db30a63066c257a1353d307f531525a86b12ec Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Sat, 13 May 2023 15:58:03 +0200 Subject: [PATCH 1/2] test: test IntSlider bug to avoid regression test #3597 --- .github/workflows/tests.yml | 2 + .../ipywidgets/widgets/tests/test_slider.py | 37 +++++++++++++++++++ python/ipywidgets/setup.cfg | 1 + 3 files changed, 40 insertions(+) create mode 100644 python/ipywidgets/ipywidgets/widgets/tests/test_slider.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e8867ae112..da0bcda947 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -105,6 +105,8 @@ jobs: python -m pip install --upgrade pip pip install file://$PWD/python/ipywidgets#egg=ipywidgets[test] - name: Test with pytest + env: + SOLARA_TEST_RUNNERS: "jupyter_notebook,jupyter_lab" run: | pip install pytest cd python/ipywidgets diff --git a/python/ipywidgets/ipywidgets/widgets/tests/test_slider.py b/python/ipywidgets/ipywidgets/widgets/tests/test_slider.py new file mode 100644 index 0000000000..1ff240d93c --- /dev/null +++ b/python/ipywidgets/ipywidgets/widgets/tests/test_slider.py @@ -0,0 +1,37 @@ +import playwright.async_api +from IPython.display import display + + +def center(locator): + box = locator.bounding_box() + x, y = box["x"] + box["width"] / 2, box["y"] + box["height"] / 2 + return x, y + + +def test_slider_tap(ipywidgets_runner, page_session: playwright.sync_api.Page): + def kernel(): + import ipywidgets as widgets + + slider = widgets.IntSlider( + continuous_update=False, + ) + text = widgets.HTML(value="Nothing happened") + + def echo(change): + if change["new"] > 0: + text.value = "slider is greater than 0" + else: + text.value = "slider is 0" + + slider.observe(echo, names="value") + slider.add_class("slider-test") + text.add_class("text-test") + display(slider) + display(text) + + ipywidgets_runner(kernel) + text = page_session.locator(".text-test") + slider = page_session.wait_for_selector(".slider-test") + x, y = center(slider) + page_session.mouse.click(x, y) + text.locator("text=slider is greater than 0").wait_for() diff --git a/python/ipywidgets/setup.cfg b/python/ipywidgets/setup.cfg index 2cb87aa8a4..dda633b5ba 100644 --- a/python/ipywidgets/setup.cfg +++ b/python/ipywidgets/setup.cfg @@ -47,6 +47,7 @@ test = pytest>=3.6.0 pytest-cov pytz + solara[pytest] [options.package_data] ipywidgets = From 05f4a95f85b9b109bf5034942a6ba78f8b818584 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Sat, 13 May 2023 16:26:27 +0200 Subject: [PATCH 2/2] ci: do not confuse pytest about where ipywidgets is --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index da0bcda947..a2a57190d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -109,8 +109,8 @@ jobs: SOLARA_TEST_RUNNERS: "jupyter_notebook,jupyter_lab" run: | pip install pytest - cd python/ipywidgets - pytest --cov=ipywidgets ipywidgets + playwright install + pytest --cov=ipywidgets --pyargs ipywidgets spec: name: Message Specification