Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
92 changes: 86 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ jobs:
make html SPHINXOPTS="-W --keep-going"

test-build-full:
name: Test examples, env with notebook and glfw
name: Test Linux, notebook + glfw
runs-on: bigmem
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
include:
- name: Test py39
pyversion: '3.9'
- name: Test py310
pyversion: '3.10'
- name: Test py311
Expand Down Expand Up @@ -103,15 +101,13 @@ jobs:
examples/notebooks/diffs

test-build-desktop:
name: Test examples, env with only glfw
name: Test Linux, only glfw
runs-on: bigmem
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
include:
- name: Test py39
pyversion: '3.9'
- name: Test py310
pyversion: '3.10'
- name: Test py311
Expand Down Expand Up @@ -156,3 +152,87 @@ jobs:
name: screenshot-diffs
path: |
examples/desktop/diffs

test-build-full-mac:
name: Test Mac, notebook + glfw
runs-on: macos-14
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
include:
- name: Test py310
pyversion: '3.10'
- name: Test py311
pyversion: '3.11'
- name: Test py312
pyversion: '3.12'
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.pyversion }}
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip setuptools
# remove pygfx from install_requires, we install using pygfx@main
pip install -e ".["tests"]"
pip install git+https://github.com/pygfx/pygfx.git@main
- name: Show wgpu backend
run:
python -c "from examples.tests.testutils import wgpu_backend; print(wgpu_backend)"
- name: Test examples
run: |
pytest -v examples
pytest --nbmake examples/notebooks/
- uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: screenshot-diffs
path: |
examples/desktop/diffs
examples/notebooks/diffs

test-build-glfw-mac:
name: Test Mac, glfw
runs-on: macos-14
if: ${{ !github.event.pull_request.draft }}
strategy:
fail-fast: false
matrix:
include:
- name: Test py310
pyversion: '3.10'
- name: Test py311
pyversion: '3.11'
- name: Test py312
pyversion: '3.12'
steps:
- uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.pyversion }}
- name: Install dev dependencies
run: |
python -m pip install --upgrade pip setuptools
# remove pygfx from install_requires, we install using pygfx@main
pip install -e ".["tests-desktop"]"
pip install git+https://github.com/pygfx/pygfx.git@main
- name: Show wgpu backend
run:
python -c "from examples.tests.testutils import wgpu_backend; print(wgpu_backend)"
- name: Test examples
run: |
pytest -v examples
- uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: screenshot-diffs
path: |
examples/desktop/diffs
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/gridplot.png
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 examples/desktop/screenshots/gridplot_non_square.png
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 examples/desktop/screenshots/heatmap.png
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 examples/desktop/screenshots/heatmap_cmap.png
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 examples/desktop/screenshots/heatmap_data.png
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 examples/desktop/screenshots/heatmap_vmin_vmax.png
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 examples/desktop/screenshots/image_cmap.png
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 examples/desktop/screenshots/image_rgb.png
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 examples/desktop/screenshots/image_rgbvminvmax.png
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 examples/desktop/screenshots/image_simple.png
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 examples/desktop/screenshots/image_vminvmax.png
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 examples/desktop/screenshots/line.png
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 examples/desktop/screenshots/line_cmap.png
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 examples/desktop/screenshots/line_collection.png
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 examples/desktop/screenshots/line_collection_colors.png
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 examples/desktop/screenshots/line_colorslice.png
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 examples/desktop/screenshots/line_dataslice.png
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 examples/desktop/screenshots/line_present_scaling.png
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 examples/desktop/screenshots/line_stack.png
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 examples/desktop/screenshots/scatter.png
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 examples/desktop/screenshots/scatter_cmap.png
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 examples/desktop/screenshots/scatter_colorslice.png
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 examples/desktop/screenshots/scatter_dataslice.png
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 examples/desktop/screenshots/scatter_present.png
4 changes: 2 additions & 2 deletions examples/desktop/screenshots/scatter_size.png
36 changes: 27 additions & 9 deletions examples/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import numpy as np
import imageio.v3 as iio
from PIL import Image

from .testutils import (
ROOT,
Expand All @@ -15,7 +16,11 @@
find_examples,
wgpu_backend,
is_lavapipe,
diffs_dir
diffs_dir,
generate_diff,
image_similarity,
normalize_image,
prep_for_write
)

# run all tests unless they opt-out
Expand Down Expand Up @@ -69,20 +74,34 @@ def test_example_screenshots(module, force_offscreen):

screenshot_path = screenshots_dir / f"{module.stem}.png"

black = np.zeros(img.shape).astype(np.uint8)
black[:, :, -1] = 255

img = np.array(
Image.alpha_composite(
Image.fromarray(black),
Image.fromarray(img.astype(np.uint8))
).convert("RGB")
)
Comment thread
kushalkolar marked this conversation as resolved.
Outdated

if "REGENERATE_SCREENSHOTS" in os.environ.keys():
if os.environ["REGENERATE_SCREENSHOTS"] == "1":
iio.imwrite(screenshot_path, img)
#np.save(screenshot_path, img)

assert (
screenshot_path.exists()
), "found # test_example = true but no reference screenshot available"
#stored_img = np.load(screenshot_path)
stored_img = iio.imread(screenshot_path)
is_similar = np.allclose(img, stored_img, atol=1)
update_diffs(module.stem, is_similar, img, stored_img)
assert is_similar, (
f"rendered image for example {module.stem} changed, see "

ref_img = iio.imread(screenshot_path)

img = normalize_image(img)
ref_img = normalize_image(ref_img)

similar, rmse = image_similarity(img, ref_img, threshold=0.025)

update_diffs(module.stem, False, img, ref_img)
assert similar, (
f"diff {rmse} above threshold for {module.stem}, see "
f"the {diffs_dir.relative_to(ROOT).as_posix()} folder"
" for visual diffs (you can download this folder from"
" CI build artifacts as well)"
Expand Down Expand Up @@ -110,7 +129,6 @@ def get_diffs_rgba(slicer):
# split into an rgb and an alpha diff
diffs = {
diffs_dir / f"diff-{module}-rgb.png": slice(0, 3),
diffs_dir / f"diff-{module}-alpha.png": 3,
}

for path, slicer in diffs.items():
Expand Down
Loading