Skip to content

Commit

Permalink
tests: use solara/pytest-ipywidgets to test image and contour
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Oct 10, 2024
1 parent 8d1590f commit 45f489d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ jobs:
echo $PWD
ls -al .
ls -al dist/
pip install dist/bqplot_image_gl*.whl jupyterlab
pip install dist/bqplot_image_gl*.whl jupyterlab "pytest-ipywidgets[solara]"
- name: Run visual regression tests
run: |
pytest tests/ui
- name: Install Galata
run: |
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/contour_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ipywidgets as widgets
import playwright.sync_api
from IPython.display import display
import numpy as np
from bqplot import Figure, LinearScale, Axis, ColorScale
from bqplot_image_gl import ImageGL, Contour


def test_widget_image(solara_test, page_session: playwright.sync_api.Page, assert_solara_snapshot):

scale_x = LinearScale(min=0, max=1)
scale_y = LinearScale(min=0, max=1)
scales = {"x": scale_x, "y": scale_y}
axis_x = Axis(scale=scale_x, label="x")
axis_y = Axis(scale=scale_y, label="y", orientation="vertical")

figure = Figure(scales=scales, axes=[axis_x, axis_y])

scales_image = {"x": scale_x, "y": scale_y, "image": ColorScale(min=0, max=2)}

x = np.linspace(0, 1, 128)
y = np.linspace(0, 1, 256)
X, Y = np.meshgrid(x, y)
data = 5. * np.sin(2 * np.pi * (X + Y**2))

image = ImageGL(image=data, scales=scales_image)
contour = Contour(image=image, level=[2, 4], scales=scales_image)


figure.marks = (image, contour)

display(figure)


svg = page_session.locator(".bqplot")
svg.wait_for()
# page_session.wait_for_timeout(1000)
assert_solara_snapshot(svg.screenshot())
32 changes: 32 additions & 0 deletions tests/ui/image_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ipywidgets as widgets
import playwright.sync_api
from IPython.display import display
import numpy as np
from bqplot import Figure, LinearScale, Axis, ColorScale
from bqplot_image_gl import ImageGL


def test_widget_image(solara_test, page_session: playwright.sync_api.Page, assert_solara_snapshot):

scale_x = LinearScale(min=0, max=1)
scale_y = LinearScale(min=0, max=1)
scales = {"x": scale_x, "y": scale_y}
axis_x = Axis(scale=scale_x, label="x")
axis_y = Axis(scale=scale_y, label="y", orientation="vertical")

figure = Figure(scales=scales, axes=[axis_x, axis_y])

scales_image = {"x": scale_x, "y": scale_y, "image": ColorScale(min=0, max=2)}

data = np.array([[0., 1.], [2., 3.]])
image = ImageGL(image=data, scales=scales_image)

figure.marks = (image,)

display(figure)


svg = page_session.locator(".bqplot")
svg.wait_for()
# page_session.wait_for_timeout(1000)
assert_solara_snapshot(svg.screenshot())
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 45f489d

Please sign in to comment.