-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2458 from astrofrog/simple-viewers
Added 'simple' viewers which can be used for testing or simple use cases
- Loading branch information
Showing
18 changed files
with
337 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
version: 2.1 | ||
|
||
jobs: | ||
|
||
# The following job is to run any visual comparison test, and runs on any branch | ||
# or in any pull request. It will generate a summary page for each tox environment | ||
# being run which is accessible through the CircleCI artifacts. | ||
|
||
visual: | ||
parameters: | ||
jobname: | ||
type: string | ||
docker: | ||
- image: cimg/python:3.11 | ||
environment: | ||
TOXENV: << parameters.jobname >> | ||
steps: | ||
- checkout | ||
- run: | ||
name: Install dependencies | ||
command: | | ||
sudo apt update | ||
pip install pip tox --upgrade | ||
- run: | ||
name: Run tests | ||
command: tox -v | ||
- store_artifacts: | ||
path: results | ||
- run: | ||
name: "Image comparison page is available at: " | ||
command: echo "${CIRCLE_BUILD_URL}/artifacts/${CIRCLE_NODE_INDEX}/results/fig_comparison.html" | ||
|
||
# The following job runs only on main - and its main purpose is to update the | ||
# reference images in the glue-core-visual-tests repository. This job needs | ||
# a deploy key. To produce this, go to the glue-core-visual-tests | ||
# repository settings and go to SSH keys, then add your public SSH key. | ||
deploy-reference-images: | ||
parameters: | ||
jobname: | ||
type: string | ||
docker: | ||
- image: cimg/python:3.11 | ||
environment: | ||
TOXENV: << parameters.jobname >> | ||
steps: | ||
- checkout | ||
- run: | ||
name: Install dependencies | ||
command: | | ||
sudo apt update | ||
pip install pip tox --upgrade | ||
- run: ssh-add -D | ||
- add_ssh_keys: | ||
fingerprints: "44:09:69:d7:c6:77:25:e9:46:da:f1:22:7d:d4:38:29" | ||
- run: ssh-keyscan github.com >> ~/.ssh/known_hosts | ||
- run: git config --global user.email "glue@circleci" && git config --global user.name "Glue Circle CI" | ||
- run: git clone [email protected]:glue-viz/glue-core-visual-tests.git --depth 1 ~/glue-core-visual-tests/ | ||
- run: | ||
name: Generate reference images | ||
command: tox -v -- --mpl-generate-path=/home/circleci/glue-core-visual-tests/images/$TOXENV | ||
- run: | | ||
cd ~/glue-core-visual-tests/ | ||
git pull | ||
git status | ||
git add . | ||
git commit -m "Update reference images from ${CIRCLE_BRANCH}" || echo "No changes to reference images to deploy" | ||
git push | ||
workflows: | ||
version: 2 | ||
|
||
visual-tests: | ||
jobs: | ||
- visual: | ||
name: << matrix.jobname >> | ||
matrix: | ||
parameters: | ||
jobname: | ||
- "py311-test-visual" | ||
|
||
- deploy-reference-images: | ||
name: baseline-<< matrix.jobname >> | ||
matrix: | ||
parameters: | ||
jobname: | ||
- "py311-test-visual" | ||
requires: | ||
- << matrix.jobname >> | ||
filters: | ||
branches: | ||
only: | ||
- main | ||
|
||
notify: | ||
webhooks: | ||
- url: https://giles.cadair.dev/circleci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,5 @@ glue/_githash.py | |
.vscode | ||
# vscode plugin | ||
.history | ||
|
||
results |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
|
||
from functools import wraps | ||
|
||
import pytest | ||
|
||
try: | ||
import pytest_mpl # noqa | ||
except ImportError: | ||
HAS_PYTEST_MPL = False | ||
else: | ||
HAS_PYTEST_MPL = True | ||
|
||
|
||
def visual_test(*args, **kwargs): | ||
""" | ||
A decorator that defines a visual test. | ||
This automatically decorates tests with mpl_image_compare with common | ||
options used by all figure tests in glue-core. | ||
""" | ||
|
||
tolerance = kwargs.pop("tolerance", 0) | ||
style = kwargs.pop("style", {}) | ||
savefig_kwargs = kwargs.pop("savefig_kwargs", {}) | ||
savefig_kwargs["metadata"] = {"Software": None} | ||
|
||
def decorator(test_function): | ||
@pytest.mark.mpl_image_compare( | ||
tolerance=tolerance, style=style, savefig_kwargs=savefig_kwargs, **kwargs | ||
) | ||
@pytest.mark.skipif( | ||
not HAS_PYTEST_MPL, reason="pytest-mpl is required for the figure tests" | ||
) | ||
@wraps(test_function) | ||
def test_wrapper(*args, **kwargs): | ||
return test_function(*args, **kwargs) | ||
|
||
return test_wrapper | ||
|
||
# If the decorator was used without any arguments, the only positional | ||
# argument will be the test to decorate so we do the following: | ||
if len(args) == 1: | ||
return decorator(*args) | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"glue.viewers.histogram.tests.test_viewer.test_simple_viewer": "cb08123fbad135ab614bb7ec13475fcc83321057d884fe80c3a32970b2d14762", | ||
"glue.viewers.image.tests.test_viewer.test_simple_viewer": "72abd60b484d14f721254f027bb0ab9b36245d5db77eb87693f4dd9998fd28be", | ||
"glue.viewers.profile.tests.test_viewer.test_simple_viewer": "f68a21be5080fec513388b2d2b220512e7b0df5498e2489da54e58708de435b3", | ||
"glue.viewers.scatter.tests.test_viewer.test_simple_viewer": "1020a7bd3abe40510b9e03047c3b423b75c3c64ac18e6dcd6257173cec1ed53f" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import numpy as np | ||
|
||
from glue.tests.visual.helpers import visual_test | ||
from glue.viewers.image.viewer import SimpleImageViewer | ||
from glue.core.application_base import Application | ||
from glue.core.data import Data | ||
|
||
|
||
@visual_test | ||
def test_simple_viewer(): | ||
|
||
# Make sure the simple viewer can be instantiated | ||
|
||
data1 = Data(x=np.arange(6).reshape((2, 3)), label='data1') | ||
data2 = Data(y=2 * np.arange(6).reshape((2, 3)), label='data2') | ||
|
||
app = Application() | ||
app.data_collection.append(data1) | ||
app.data_collection.append(data2) | ||
|
||
viewer = app.new_data_viewer(SimpleImageViewer) | ||
viewer.add_data(data1) | ||
viewer.add_data(data2) | ||
|
||
app.data_collection.new_subset_group(label='subset1', subset_state=data1.pixel_component_ids[1] > 1.2) | ||
|
||
return viewer.figure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from glue.tests.visual.helpers import visual_test | ||
from glue.viewers.profile.viewer import SimpleProfileViewer | ||
from glue.core.application_base import Application | ||
from glue.core.data import Data | ||
|
||
|
||
@visual_test | ||
def test_simple_viewer(): | ||
|
||
# Make sure the simple viewer can be instantiated | ||
|
||
data1 = Data(x=[1, 2, 3], label='data1') | ||
data2 = Data(y=[1, 2, 3], label='data2') | ||
|
||
app = Application() | ||
app.data_collection.append(data1) | ||
app.data_collection.append(data2) | ||
|
||
viewer = app.new_data_viewer(SimpleProfileViewer) | ||
viewer.add_data(data1) | ||
viewer.add_data(data2) | ||
|
||
app.data_collection.new_subset_group(label='subset1', subset_state=data1.pixel_component_ids[0] > 0.8) | ||
|
||
viewer.state.layers[2].linewidth = 5 | ||
|
||
return viewer.figure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.