diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index b1bb3c6..a880407 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -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: | @@ -98,6 +102,7 @@ jobs: path: | ui-tests/playwright-report ui-tests/test-results + test-results tests: uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 diff --git a/tests/ui/contour_test.py b/tests/ui/contour_test.py new file mode 100644 index 0000000..82d3453 --- /dev/null +++ b/tests/ui/contour_test.py @@ -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()) diff --git a/tests/ui/image_test.py b/tests/ui/image_test.py new file mode 100644 index 0000000..71b99e3 --- /dev/null +++ b/tests/ui/image_test.py @@ -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()) diff --git a/tests/ui/snapshots/tests/ui/contour_test.py/test_widget_image-chromium-darwin-reference.png b/tests/ui/snapshots/tests/ui/contour_test.py/test_widget_image-chromium-darwin-reference.png new file mode 100644 index 0000000..a78b6b5 Binary files /dev/null and b/tests/ui/snapshots/tests/ui/contour_test.py/test_widget_image-chromium-darwin-reference.png differ diff --git a/tests/ui/snapshots/tests/ui/image_test.py/test_widget_image-chromium-darwin-reference.png b/tests/ui/snapshots/tests/ui/image_test.py/test_widget_image-chromium-darwin-reference.png new file mode 100644 index 0000000..a579492 Binary files /dev/null and b/tests/ui/snapshots/tests/ui/image_test.py/test_widget_image-chromium-darwin-reference.png differ