Skip to content

Commit 18aee48

Browse files
authored
Merge pull request matplotlib#20190 from anntzer/uncomparable
Simplify handling of uncomparable formats in tests.
2 parents 70dbc7c + 86d4d83 commit 18aee48

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,6 @@ def _raise_on_image_difference(expected, actual, tol):
141141
'\n\t%(actual)s\n\t%(expected)s\n\t%(diff)s') % err)
142142

143143

144-
def _skip_if_format_is_uncomparable(extension):
145-
import pytest
146-
return pytest.mark.skipif(
147-
extension not in comparable_formats(),
148-
reason='Cannot compare {} files on this system'.format(extension))
149-
150-
151-
def _mark_skip_if_format_is_uncomparable(extension):
152-
import pytest
153-
if isinstance(extension, str):
154-
name = extension
155-
marks = []
156-
elif isinstance(extension, tuple):
157-
# Extension might be a pytest ParameterSet instead of a plain string.
158-
# Unfortunately, this type is not exposed, so since it's a namedtuple,
159-
# check for a tuple instead.
160-
name, = extension.values
161-
marks = [*extension.marks]
162-
else:
163-
# Extension might be a pytest marker instead of a plain string.
164-
name, = extension.args
165-
marks = [extension.mark]
166-
return pytest.param(name,
167-
marks=[*marks, _skip_if_format_is_uncomparable(name)])
168-
169-
170144
class _ImageComparisonBase:
171145
"""
172146
Image comparison base class
@@ -238,7 +212,6 @@ def _pytest_image_comparison(baseline_images, extensions, tol,
238212
"""
239213
import pytest
240214

241-
extensions = map(_mark_skip_if_format_is_uncomparable, extensions)
242215
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
243216

244217
def decorator(func):
@@ -256,6 +229,9 @@ def wrapper(*args, extension, request, **kwargs):
256229
if 'request' in old_sig.parameters:
257230
kwargs['request'] = request
258231

232+
if extension not in comparable_formats():
233+
pytest.skip(f"Cannot compare {extension} files on this system")
234+
259235
img = _ImageComparisonBase(func, tol=tol, remove_text=remove_text,
260236
savefig_kwargs=savefig_kwargs)
261237
matplotlib.testing.set_font_settings_for_testing()

0 commit comments

Comments
 (0)