Skip to content

Commit 7914a22

Browse files
committed
Add inital image comparison tests for transects
1 parent 52b0f84 commit 7914a22

File tree

9 files changed

+38
-7
lines changed

9 files changed

+38
-7
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ jobs:
8383
shell: bash -l {0}
8484
run: |
8585
pytest -v \
86+
--mpl \
87+
--mpl-results-path=./mpl-results \
88+
--mpl-generate-summary html \
8689
--junitxml=junit-py${{ matrix.python-version }}.xml \
8790
--cov --cov-report term \
8891
--cov-report xml:coverage-${{ matrix.python-version }}.xml
@@ -94,6 +97,15 @@ jobs:
9497
report_paths: 'junit-py*.xml'
9598
check_name: "JUnit Test Report - Python ${{ matrix.python-version }}"
9699

100+
- name: MPL image comparison report
101+
uses: actions/upload-artifact@v3
102+
if: ${{ failure() }}
103+
with:
104+
name: "MPL image comparison report - Python ${{ matrix.python-version }}"
105+
path: './mpl-results'
106+
# No guarantee that the test failures were due to image comparisons
107+
if-no-files-found: 'ignore'
108+
97109
- uses: actions/upload-artifact@v3
98110
with:
99111
name: Code coverage for Python ${{ matrix.python-version }}

continuous-integration/requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jinja2==3.1.2
9898
# bokeh
9999
# dask
100100
# distributed
101+
# pytest-mpl
101102
# sphinx
102103
kiwisolver==1.4.4
103104
# via matplotlib
@@ -115,6 +116,7 @@ matplotlib==3.7.2
115116
# via
116117
# cartopy
117118
# emsarray (setup.cfg)
119+
# pytest-mpl
118120
mccabe==0.7.0
119121
# via flake8
120122
msgpack==1.0.5
@@ -156,6 +158,7 @@ packaging==23.1
156158
# pydata-sphinx-theme
157159
# pyproject-api
158160
# pytest
161+
# pytest-mpl
159162
# sphinx
160163
# tox
161164
# xarray
@@ -172,6 +175,7 @@ pillow==10.0.0
172175
# via
173176
# bokeh
174177
# matplotlib
178+
# pytest-mpl
175179
platformdirs==3.10.0
176180
# via
177181
# pooch
@@ -214,8 +218,11 @@ pytest==7.4.0
214218
# via
215219
# emsarray (setup.cfg)
216220
# pytest-cov
221+
# pytest-mpl
217222
pytest-cov==4.1.0
218223
# via emsarray (setup.cfg)
224+
pytest-mpl==0.16.1
225+
# via emsarray (setup.cfg)
219226
python-dateutil==2.8.2
220227
# via
221228
# matplotlib

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ requires = [
55
build-backend = "setuptools.build_meta"
66

77
[tool.pytest.ini_options]
8+
addopts = [
9+
# TODO Work around till the mpl-baseline-path ini option is included in the
10+
# next pytest-mpl release.
11+
"--mpl-baseline-path", "tests/baseline_images",
12+
]
13+
814
testpaths = ["tests"]
915
filterwarnings = [
1016
"error",
@@ -18,6 +24,11 @@ markers = [
1824
"tutorial: Tests that involve the tutorial datasets",
1925
]
2026

27+
mpl-use-full-test-name = true
28+
# TODO This option will be included in the next version of pytest-mpl.
29+
# Till then, it is added using addopts above
30+
# mpl-baseline-path = "tests/baseline_images"
31+
2132
[tool.mypy]
2233
python_version = "3.9"
2334
plugins = ["numpy.typing.mypy_plugin"]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ testing =
6363
%(docs)s
6464
pytest
6565
pytest-cov
66+
pytest-mpl
6667
mypy
6768
pandas-stubs
6869
types-pytz
114 KB
Loading
41.3 KB
Loading
33.4 KB
Loading

tests/test_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_add_landmarks():
5252
assert text.xy == landmark[1].coords.xy
5353

5454

55+
@pytest.mark.mpl_image_compare
5556
@pytest.mark.matplotlib(mock_coast=True)
5657
@pytest.mark.tutorial
5758
def test_plot(
@@ -68,8 +69,7 @@ def test_plot(
6869
axes = figure.axes[0]
6970
assert axes.get_title() == 'Temperature\n2022-05-11T14:00'
7071

71-
matplotlib.pyplot.savefig(tmp_path / 'plot.png')
72-
logger.info("Saved plot to %r", tmp_path / 'plot.png')
72+
return figure
7373

7474

7575
@pytest.mark.matplotlib(mock_coast=True)

tests/test_transect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
logger = logging.getLogger(__name__)
1111

1212

13-
@pytest.mark.matplotlib(mock_coast=True)
13+
@pytest.mark.mpl_image_compare
14+
@pytest.mark.matplotlib
1415
@pytest.mark.tutorial
1516
def test_plot(
1617
datasets: pathlib.Path,
@@ -53,10 +54,10 @@ def test_plot(
5354
# This is the variable units
5455
assert colorbar.get_ylabel() == 'degrees C'
5556

56-
matplotlib.pyplot.savefig(tmp_path / 'plot.png')
57-
logger.info("Saved plot to %r", tmp_path / 'plot.png')
57+
return figure
5858

5959

60+
@pytest.mark.mpl_image_compare
6061
@pytest.mark.matplotlib(mock_coast=True)
6162
@pytest.mark.tutorial
6263
def test_plot_no_intersection(
@@ -95,5 +96,4 @@ def test_plot_no_intersection(
9596
# This is the variable units
9697
assert colorbar.get_ylabel() == 'degrees C'
9798

98-
matplotlib.pyplot.savefig(tmp_path / 'plot.png')
99-
logger.info("Saved plot to %r", tmp_path / 'plot.png')
99+
return figure

0 commit comments

Comments
 (0)