Skip to content

Commit c186408

Browse files
committed
Handle comments from PR.
* Install nose in one build. * Add docstrings and comments on new functions/classes to clarify what they do. * Use consistent `yield` pattern for fixture.
1 parent ba7106a commit c186408

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ env:
4545
- NPROC=2
4646
- INSTALL_PEP8=
4747
- RUN_PEP8=
48+
- NOSE=
4849
- PYTEST_ARGS="-ra --maxfail=1 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
4950
- PYTHON_ARGS=
5051
- DELETE_FONT_CACHE=
5152

5253
matrix:
5354
include:
5455
- python: 2.7
55-
env: MOCK=mock NUMPY=numpy==1.7.1 PANDAS=pandas
56+
env: MOCK=mock NUMPY=numpy==1.7.1 PANDAS=pandas NOSE=nose
5657
- python: 2.7
5758
env: BUILD_DOCS=true
5859
- python: 3.4
@@ -114,7 +115,7 @@ install:
114115
pip install --upgrade setuptools
115116
- |
116117
# Install dependencies from pypi
117-
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler codecov coverage $MOCK
118+
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler codecov coverage $MOCK $NOSE
118119
pip install $PRE -r doc-requirements.txt
119120
120121
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124

lib/matplotlib/testing/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@ def mpl_image_comparison_parameters(request, extension):
7373

7474
func = request.function
7575
func.__wrapped__.parameters = (baseline_images, extension)
76-
yield
77-
delattr(func.__wrapped__, 'parameters')
76+
try:
77+
yield
78+
finally:
79+
delattr(func.__wrapped__, 'parameters')

lib/matplotlib/testing/decorators.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ def _mark_xfail_if_format_is_uncomparable(extension):
234234

235235

236236
class _ImageComparisonBase(object):
237+
"""
238+
Image comparison base class
239+
240+
This class provides *just* the comparison-related functionality and avoids
241+
any code that would be specific to any testing framework.
242+
"""
237243
def __init__(self, tol, remove_text, savefig_kwargs):
238244
self.func = self.baseline_dir = self.result_dir = None
239245
self.tol = tol
@@ -282,6 +288,15 @@ def compare(self, idx, baseline, extension):
282288

283289

284290
class ImageComparisonTest(CleanupTest, _ImageComparisonBase):
291+
"""
292+
Nose-based image comparison class
293+
294+
This class generates tests for a nose-based testing framework. Ideally,
295+
this class would not be public, and the only publically visible API would
296+
be the :func:`image_comparison` decorator. Unfortunately, there are
297+
existing downstream users of this class (e.g., pytest-mpl) so it cannot yet
298+
be removed.
299+
"""
285300
def __init__(self, baseline_images, extensions, tol,
286301
freetype_version, remove_text, savefig_kwargs, style):
287302
_ImageComparisonBase.__init__(self, tol, remove_text, savefig_kwargs)
@@ -339,14 +354,24 @@ def runner_wrapper():
339354
def _pytest_image_comparison(baseline_images, extensions, tol,
340355
freetype_version, remove_text, savefig_kwargs,
341356
style):
357+
"""
358+
Decorate function with image comparison for pytest.
359+
360+
This function creates a decorator that wraps a figure-generating function
361+
with image comparison code. Pytest can become confused if we change the
362+
signature of the function, so we indirectly pass anything we need via the
363+
`mpl_image_comparison_parameters` fixture and extra markers.
364+
"""
342365
import pytest
343366

344367
extensions = map(_mark_xfail_if_format_is_uncomparable, extensions)
345368

346369
def decorator(func):
370+
# Parameter indirection; see docstring above and comment below.
347371
@pytest.mark.usefixtures('mpl_image_comparison_parameters')
348372
@pytest.mark.parametrize('extension', extensions)
349373
@pytest.mark.baseline_images(baseline_images)
374+
# END Parameter indirection.
350375
@pytest.mark.style(style)
351376
@_checked_on_freetype_version(freetype_version)
352377
@functools.wraps(func)
@@ -358,6 +383,7 @@ def wrapper(*args, **kwargs):
358383
matplotlib.testing.set_font_settings_for_testing()
359384
func(*args, **kwargs)
360385

386+
# Parameter indirection:
361387
# This is hacked on via the mpl_image_comparison_parameters fixture
362388
# so that we don't need to modify the function's real signature for
363389
# any parametrization. Modifying the signature is very very tricky

0 commit comments

Comments
 (0)