Skip to content

Commit

Permalink
Update testing matrix, start using image comparison (#40)
Browse files Browse the repository at this point in the history
* Update testing matrix, start using image comparison

* Update checkout action

* Update reference images

* Handle scientific notation output from odiff

* Use images generated by github runner as ref

* Increase image diff tolerance

* Patch version bump
  • Loading branch information
A-CGray authored Feb 14, 2024
1 parent 7892f4c commit b23b4d8
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 18 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/niceplots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
numpy-version: ["1.19.*", "1.21.*", "1.24.*"]
mpl-version: ["3.4.*", "3.6.*"]
exclude:
- python-version: "3.9"
numpy-version: "1.19.*"
- python-version: "3.10"
numpy-version: "1.19.*"
matrix: # Test 3 versions of python, and the latest and oldest supported versions of numpy and matplotlib, according to https://scientific-python.org/specs/spec-0000/
python-version: ["3.9", "3.10", "3.11"]
numpy-version: ["1.23.*", "1.26.*"]
mpl-version: ["3.6.*", "3.8.*"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -61,13 +56,13 @@ jobs:
cd examples
bash testExamples.sh
- name: Compare against reference images
if: ${{ success() && matrix.python-version == '3.10' && matrix.numpy-version == '1.24.*' && matrix.mpl-version == '3.6.*' }}
if: ${{ success() && matrix.python-version == '3.11' && matrix.numpy-version == '1.26.*' && matrix.mpl-version == '3.8.*' }}
run: |
cd examples
bash ImageComparisonTest.sh
- name: Upload examples if failed
uses: actions/upload-artifact@v3
if: ${{ failure() && matrix.python-version == '3.10' && matrix.numpy-version == '1.24.*' && matrix.mpl-version == '3.6.*' }}
if: ${{ failure() && matrix.python-version == '3.11' && matrix.numpy-version == '1.26.*' && matrix.mpl-version == '3.8.*' }}
with:
name: Examples
path: examples/
Expand Down
21 changes: 16 additions & 5 deletions examples/ImageComparisonTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# This script compares the images generated by the example scripts to a set of reference images

test_passed=true # Kepp track of whether any tests fail
test_passed=true # Keep track of whether any tests fail
tolerance=0.05

# First check that there aren't any images produced by the examples that don't have a reference image
for f in *.png
Expand All @@ -25,9 +26,19 @@ do
if test -f "$base_name"; then
filename_no_ext="${base_name%.*}"
echo "Comparing $base_name and $f"
odiff --antialiasing --threshold=0.1 --diff-mask $base_name $f diffs/${filename_no_ext}-diff.png
if [ $? -ne 0 ]; then
test_passed=false
output=$(odiff --parsable-stdout --antialiasing --diff-mask $base_name $f diffs/${filename_no_ext}-diff.png)
# echo "$output"
if [[ -z "$output" ]]; then
echo "Images match"
else
outputArray=(${output//;/ }) # Split the output by the semicolon
diffPixels=${outputArray[0]}
diffPercentage=$(printf "%.8f\n" ${outputArray[1]}) # use printf to convert scientific notation to decimal
echo "Difference = $diffPixels pixels ($diffPercentage %)"
if (( $(echo "$diffPercentage > $tolerance" | bc -l) )); then
echo "Difference is greater than $tolerance % so test failed"
test_passed=false
fi
fi
else
echo "Couldn't find image to compare against $f"
Expand All @@ -44,5 +55,5 @@ if [ "$test_passed" = true ] ; then
else
echo "Some comparisons failed"
echo "==========================="
exit 0 # In future (if we can make the image comparison more robust) we should exit with a non-zero exit code (e.g. 1)
exit 1
fi
Binary file modified examples/ref/bar_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/colored_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/colored_line_custom_norm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/default_style_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/doumont-dark_style_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/doumont-light_style_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/james-dark_style_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/james-light_style_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/line_end_labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/nested_pie_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/opt_prob-hashed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/opt_prob-shaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/opt_stacks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/opt_stacks_more_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/parula_contours.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/ref/style_color_demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion niceplots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.5.0"
__version__ = "2.5.1"

from .utils import *
from .parula import *

0 comments on commit b23b4d8

Please sign in to comment.