Skip to content

Commit b0783eb

Browse files
authored
Merge pull request #87 from astrofrog/refactor-infrastructure
Package infrastructure cleanup
2 parents 213e46f + ff26395 commit b0783eb

File tree

10 files changed

+201
-190
lines changed

10 files changed

+201
-190
lines changed

.travis.yml

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,52 @@
1-
language: c
1+
language: python
22

3-
# Setting sudo to false opts in to Travis-CI container-based builds.
43
sudo: false
54

6-
os:
7-
- linux
8-
- osx
9-
105
env:
116
global:
127
- SETUP_XVFB=True
13-
- CONDA_DEPENDENCIES="pytest matplotlib nose coverage freetype=2.5.5"
14-
- PIP_DEPENDENCIES="pytest-cov coveralls"
15-
matrix:
16-
- PYTHON_VERSION=3.4 MATPLOTLIB_VERSION=1.5
17-
- PYTHON_VERSION=2.7 MATPLOTLIB_VERSION=1.5
18-
- PYTHON_VERSION=3.5 MATPLOTLIB_VERSION=1.5
19-
- PYTHON_VERSION=2.7 MATPLOTLIB_VERSION=2.0
20-
- PYTHON_VERSION=3.5 MATPLOTLIB_VERSION=2.0
21-
- PYTHON_VERSION=3.6 MATPLOTLIB_VERSION=2.0
22-
23-
# The following build is meant to check that dependencies get set up correctly, but currently
24-
# the image tests fail, which should be investigated.
25-
# - PYTHON_VERSION=3.5 CONDA_DEPENDENCIES="coverage freetype libpng"
8+
- TOXENV='test'
9+
- TOXARGS='-v'
10+
- TOXPOSARGS=''
11+
12+
matrix:
13+
include:
14+
# Test the oldest and newest configuration on Mac and Windows
15+
- os: osx
16+
language: c
17+
env: PYTHON_VERSION=3.6 TOXENV=py36-test-mpl20
18+
- os: osx
19+
language: c
20+
env: PYTHON_VERSION=3.8 TOXENV=py38-test-mpl31
21+
- os: windows
22+
language: c
23+
env: PYTHON_VERSION=3.6 TOXENV=py36-test-mpl20
24+
- os: windows
25+
language: c
26+
env: PYTHON_VERSION=3.8 TOXENV=py38-test-mpl31
27+
# Test all configurations on Linux
28+
- python: 3.6
29+
env: TOXENV=py36-test-mpl20
30+
- python: 3.6
31+
env: TOXENV=py36-test-mpl21
32+
- python: 3.6
33+
env: TOXENV=py36-test-mpl22
34+
- python: 3.7
35+
env: TOXENV=py37-test-mpl30
36+
- python: 3.8
37+
env: TOXENV=py38-test-mpl31
38+
- python: 3.8
39+
env: TOXENV=codestyle
2640

2741
install:
28-
29-
# We use the ci-helpers package from the Astropy project to set up conda
30-
# with any requested dependencies above.
31-
- git clone git://github.com/astropy/ci-helpers.git
32-
- source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh
33-
34-
# Need to use develop instead of install to make sure coverage works
35-
- python setup.py develop
42+
- if [[ $TRAVIS_OS_NAME != linux ]]; then
43+
git clone git://github.com/astropy/ci-helpers.git;
44+
source ci-helpers/travis/setup_conda.sh;
45+
fi
3646

3747
script:
38-
- python -c 'import pytest_mpl.plugin'
39-
- pytest -vv --mpl --cov pytest_mpl tests
40-
# Make sure that the tests run ok even without the --mpl option (we close
41-
# figures anyway in this case)
42-
- pytest -vv --cov pytest_mpl --cov-append tests
43-
- python setup.py check --restructuredtext
48+
- pip install tox
49+
- tox $TOXARGS -- $TOXPOSARGS
4450

4551
after_success:
46-
- coveralls
52+
- coveralls

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
- Properly register mpl_image_compare marker with pytest. [#83]
1212

13+
- Drop support for Python 3.5 and earlier, and Matplotlib 1.5. [#87]
14+
1315
0.10 (2018-09-25)
1416
-----------------
1517

README.rst

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
|Travis Build Status| |AppVeyor Build status| |Coveralls coverage|
1+
|Travis Build Status| |Coveralls coverage|
22

33
About
44
-----
55

66
This is a plugin to facilitate image comparison for
77
`Matplotlib <http://www.matplotlib.org>`__ figures in pytest.
88

9-
Matplotlib includes a number of test utilities and decorators, but these
10-
are geared towards the `nose <http://nose.readthedocs.org/>`__ testing
11-
framework. Pytest-mpl makes it easy to compare figures produced by tests
12-
to reference images when using `pytest <http://pytest.org>`__.
13-
149
For each figure to test, the reference image is subtracted from the
1510
generated image, and the RMS of the residual is compared to a
1611
user-specified tolerance. If the residual is too large, the test will
@@ -23,23 +18,17 @@ section below.
2318
Installing
2419
----------
2520

26-
This plugin is compatible with Python 2.6, 2.7, and 3.3 and later, and
27-
requires `pytest <http://pytest.org>`__,
28-
`matplotlib <http://www.matplotlib.org>`__ and
29-
`nose <http://nose.readthedocs.org/>`__ to be installed (nose is
30-
required by Matplotlib).
31-
32-
To install, you can do:
21+
This plugin is compatible with Python 2.7, and 3.5 and later, and
22+
requires `pytest <http://pytest.org>`__ and
23+
`matplotlib <http://www.matplotlib.org>` to be installed.
3324

34-
::
25+
To install, you can do::
3526

3627
pip install pytest-mpl
3728

38-
You can check that the plugin is registered with pytest by doing:
39-
40-
::
29+
You can check that the plugin is registered with pytest by doing::
4130

42-
py.test --version
31+
pytest --version
4332

4433
which will show a list of plugins:
4534

@@ -71,24 +60,20 @@ function returns a Matplotlib figure (or any figure object that has a
7160
7261
To generate the baseline images, run the tests with the
7362
``--mpl-generate-path`` option with the name of the directory where the
74-
generated images should be placed:
75-
76-
::
63+
generated images should be placed::
7764

78-
py.test --mpl-generate-path=baseline
65+
pytest --mpl-generate-path=baseline
7966

8067
If the directory does not exist, it will be created. The directory will
81-
be interpreted as being relative to where you are running ``py.test``.
68+
be interpreted as being relative to where you are running ``pytest``.
8269
Once you are happy with the generated images, you should move them to a
8370
sub-directory called ``baseline`` relative to the test files (this name
8471
is configurable, see below). You can also generate the baseline images
8572
directly in the right directory.
8673

87-
You can then run the tests simply with:
74+
You can then run the tests simply with::
8875

89-
::
90-
91-
py.test --mpl
76+
pytest --mpl
9277

9378
and the tests will pass if the images are the same. If you omit the
9479
``--mpl`` option, the tests will run but will only check that the code
@@ -145,11 +130,9 @@ a comma-separated list of URLs (real commas in the URL should be encoded
145130
as ``%2C``).
146131

147132
Finally, you can also set a custom baseline directory globally when
148-
running tests by running ``py.test`` with:
149-
150-
::
133+
running tests by running ``pytest`` with::
151134

152-
py.test --mpl --mpl-baseline-path=baseline_images
135+
pytest --mpl --mpl-baseline-path=baseline_images
153136

154137
This directory will be interpreted as being relative to where the tests
155138
are run. In addition, if both this option and the ``baseline_dir``
@@ -190,9 +173,7 @@ Test failure example
190173

191174
If the images produced by the tests are correct, then the test will
192175
pass, but if they are not, the test will fail with a message similar to
193-
the following:
194-
195-
::
176+
the following::
196177

197178
E Exception: Error: Image files did not match.
198179
E RMS Value: 142.2287807767823
@@ -226,7 +207,7 @@ By default, the expected, actual and difference files are written to a
226207
temporary directory with a non-deterministic path. If you want to instead
227208
write them to a specific directory, you can use::
228209

229-
py.test --mpl --mpl-results-path=results
210+
pytest --mpl --mpl-results-path=results
230211

231212
The ``results`` directory will then contain one sub-directory per test, and each
232213
sub-directory will contain the three files mentioned above. If you are using a
@@ -242,20 +223,16 @@ Running the tests for pytest-mpl
242223
--------------------------------
243224

244225
If you are contributing some changes and want to run the tests, first
245-
install the latest version of the plugin then do:
246-
247-
::
226+
install the latest version of the plugin then do::
248227

249228
cd tests
250-
py.test --mpl
229+
pytest --mpl
251230

252231
The reason for having to install the plugin first is to ensure that the
253232
plugin is correctly loaded as part of the test suite.
254233

255234
.. |Travis Build Status| image:: https://travis-ci.org/matplotlib/pytest-mpl.svg?branch=master
256235
:target: https://travis-ci.org/matplotlib/pytest-mpl
257-
.. |AppVeyor Build status| image:: https://ci.appveyor.com/api/projects/status/mf7hs44scg5mvcyo?svg=true
258-
:target: https://ci.appveyor.com/project/astrofrog/pytest-mpl
259236
.. |Coveralls coverage| image:: https://coveralls.io/repos/matplotlib/pytest-mpl/badge.svg
260237
:target: https://coveralls.io/r/matplotlib/pytest-mpl
261238
.. |expected| image:: images/baseline-coords_overlay_auto_coord_meta.png

appveyor.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

pytest_mpl/plugin.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _download_file(baseline, filename):
6363
try:
6464
u = urlopen(base_url + filename)
6565
content = u.read()
66-
except Exception as exc:
66+
except Exception:
6767
warnings.warn('Downloading {0} failed'.format(base_url + filename))
6868
else:
6969
break
@@ -104,7 +104,9 @@ def pytest_addoption(parser):
104104

105105
def pytest_configure(config):
106106

107-
config.addinivalue_line('markers', "mpl_image_compare: Compares matplotlib figures against a baseline image")
107+
config.addinivalue_line('markers',
108+
"mpl_image_compare: Compares matplotlib figures "
109+
"against a baseline image")
108110

109111
if config.getoption("--mpl") or config.getoption("--mpl-generate-path") is not None:
110112

@@ -192,8 +194,8 @@ def pytest_runtest_setup(self, item):
192194
if compare is None:
193195
return
194196

195-
from PIL import Image
196197
import matplotlib
198+
from matplotlib.image import imread
197199
import matplotlib.pyplot as plt
198200
from matplotlib.testing.compare import compare_images
199201
try:
@@ -269,23 +271,28 @@ def item_function_wrapper(*args, **kwargs):
269271
if baseline_remote:
270272
baseline_image_ref = _download_file(baseline_dir, filename)
271273
else:
272-
baseline_image_ref = os.path.abspath(os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir, filename))
274+
baseline_image_ref = os.path.abspath(os.path.join(
275+
os.path.dirname(item.fspath.strpath), baseline_dir, filename))
273276

274277
if not os.path.exists(baseline_image_ref):
275278
pytest.fail("Image file not found for comparison test in: "
276279
"\n\t{baseline_dir}"
277280
"\n(This is expected for new tests.)\nGenerated Image: "
278-
"\n\t{test}".format(baseline_dir=baseline_dir, test=test_image), pytrace=False)
281+
"\n\t{test}".format(baseline_dir=baseline_dir,
282+
test=test_image),
283+
pytrace=False)
279284

280285
# distutils may put the baseline images in non-accessible places,
281286
# copy to our tmpdir to be sure to keep them in case of failure
282-
baseline_image = os.path.abspath(os.path.join(result_dir, 'baseline-' + filename))
287+
baseline_image = os.path.abspath(os.path.join(result_dir,
288+
'baseline-' + filename))
283289
shutil.copyfile(baseline_image_ref, baseline_image)
284290

285-
# Compare image size ourselves since the Matplotlib exception is a bit cryptic in this case
286-
# and doesn't show the filenames
287-
expected_shape = Image.open(baseline_image).size
288-
actual_shape = Image.open(test_image).size
291+
# Compare image size ourselves since the Matplotlib
292+
# exception is a bit cryptic in this case and doesn't show
293+
# the filenames
294+
expected_shape = imread(baseline_image).shape[:2]
295+
actual_shape = imread(test_image).shape[:2]
289296
if expected_shape != actual_shape:
290297
error = SHAPE_MISMATCH_ERROR.format(expected_path=baseline_image,
291298
expected_shape=expected_shape,
@@ -305,7 +312,8 @@ def item_function_wrapper(*args, **kwargs):
305312
if not os.path.exists(self.generate_dir):
306313
os.makedirs(self.generate_dir)
307314

308-
fig.savefig(os.path.abspath(os.path.join(self.generate_dir, filename)), **savefig_kwargs)
315+
fig.savefig(os.path.abspath(os.path.join(self.generate_dir, filename)),
316+
**savefig_kwargs)
309317
close_mpl_figure(fig)
310318
pytest.skip("Skipping test, since generating data")
311319

@@ -331,8 +339,6 @@ def pytest_runtest_setup(self, item):
331339
if compare is None:
332340
return
333341

334-
import matplotlib.pyplot as plt
335-
336342
original = item.function
337343

338344
@wraps(item.function)

setup.cfg

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
11
[metadata]
22
license_file = LICENSE
3+
name = pytest-mpl
4+
version = 0.11
5+
url = https://github.com/matplotlib/pytest-mpl
6+
author = Thomas Robitaille
7+
author_email = thomas.robitaille@gmail.com
8+
classifiers =
9+
Development Status :: 4 - Beta
10+
Framework :: Pytest
11+
Intended Audience :: Developers
12+
Topic :: Software Development :: Testing
13+
Topic :: Scientific/Engineering :: Visualization
14+
Programming Language :: Python
15+
Programming Language :: Python :: 2
16+
Programming Language :: Python :: 3
17+
Operating System :: OS Independent
18+
License :: OSI Approved :: BSD License
19+
license = BSD
20+
description = pytest plugin to help with testing figures output from Matplotlib
21+
long_description = file: README.rst
22+
23+
[options]
24+
zip_safe = True
25+
packages = find:
26+
install_requires =
27+
pytest
28+
matplotlib
29+
30+
[options.entry_points]
31+
pytest11 =
32+
pytest_mpl = pytest_mpl.plugin
33+
34+
[options.extras_require]
35+
test =
36+
pytest-cov
37+
38+
[tool:pytest]
39+
testpaths = "tests"

0 commit comments

Comments
 (0)