Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: use solara/pytest-ipywidgets to test image and contour #108

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 9 additions & 30 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine wheel jupyter-packaging jupyterlab
pip install twine wheel jupyter-packaging "jupyterlab<4"

- name: Build
run: |
Expand All @@ -50,12 +50,6 @@ jobs:
name: bqplot-image-gl-dist-${{ github.run_number }}
path: ./dist

- name: Install node
uses: actions/setup-node@v2
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install Python
uses: actions/setup-python@v2
with:
Expand All @@ -66,38 +60,23 @@ jobs:
echo $PWD
ls -al .
ls -al dist/
pip install dist/bqplot_image_gl*.whl jupyterlab
pip install dist/bqplot_image_gl*.whl "pytest-ipywidgets[all]"

- name: Install Galata
- name: Install playwright
run: |
yarn install
yarn playwright install chromium
working-directory: ui-tests

- name: Launch JupyterLab
run: yarn run start:detached
working-directory: ui-tests
playwright install chromium

- name: Wait for JupyterLab
uses: ifaxity/wait-on-action@v1
with:
resource: http-get://localhost:8988/api
timeout: 20000

- name: Run UI Tests
env:
TARGET_URL: http://127.0.0.1:8988
run: yarn run test
working-directory: ui-tests
- name: Run visual regression tests
run: |
pytest tests/ui

- name: Upload UI Test artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: ui-test-output
name: bqplot-image-gl-ui-test-output
path: |
ui-tests/playwright-report
ui-tests/test-results
test-results

tests:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
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())
35 changes: 35 additions & 0 deletions tests/ui/image_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ipywidgets as widgets
import playwright.sync_api
from IPython.display import display



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

def kernel_code():
import numpy as np
from bqplot import Figure, LinearScale, Axis, ColorScale
from bqplot_image_gl import ImageGL
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)

ipywidgets_runner(kernel_code)
svg = page_session.locator(".bqplot")
svg.wait_for()
# make sure the image is rendered
page_session.wait_for_timeout(100)
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.
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.
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.
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.
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.
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ changedir =
deps =
test: pytest
test: pytest-cov
test: notebook
test: notebook<7
notebooks: numpy
notebooks: ipyvuetify
notebooks: scikit-image
notebooks: notebook
notebooks: notebook<7
# NOTE: the following is a temporary fix for the issue described in
# https://github.com/voila-dashboards/voila/issues/728
# and should be removed once the issue is fixed in jupyter-server
Expand Down
41 changes: 0 additions & 41 deletions ui-tests/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions ui-tests/jupyter_server_config.py

This file was deleted.

21 changes: 0 additions & 21 deletions ui-tests/package.json

This file was deleted.

7 changes: 0 additions & 7 deletions ui-tests/playwright.config.js

This file was deleted.

134 changes: 0 additions & 134 deletions ui-tests/tests/bqplot-image-gl.test.ts

This file was deleted.

Binary file not shown.
Loading
Loading