Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8effa93

Browse files
authored
Merge pull request #10905 from anntzer/knownfailureif
MNT/TST: Inline knownfailureif.
2 parents c65c14d + 49e2b0e commit 8effa93

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,6 @@
2626
from .exceptions import ImageComparisonFailure
2727

2828

29-
def _knownfailureif(fail_condition, msg=None, known_exception_class=None):
30-
"""
31-
32-
Assume a will fail if *fail_condition* is True. *fail_condition*
33-
may also be False or the string 'indeterminate'.
34-
35-
*msg* is the error message displayed for the test.
36-
37-
If *known_exception_class* is not None, the failure is only known
38-
if the exception is an instance of this class. (Default = None)
39-
40-
"""
41-
import pytest
42-
if fail_condition == 'indeterminate':
43-
fail_condition, strict = True, False
44-
else:
45-
fail_condition, strict = bool(fail_condition), True
46-
return pytest.mark.xfail(condition=fail_condition, reason=msg,
47-
raises=known_exception_class, strict=strict)
48-
49-
5029
def _do_cleanup(original_units_registry, original_settings):
5130
plt.close('all')
5231

@@ -151,14 +130,13 @@ def check_freetype_version(ver):
151130

152131

153132
def _checked_on_freetype_version(required_freetype_version):
154-
if check_freetype_version(required_freetype_version):
155-
return lambda f: f
156-
133+
import pytest
157134
reason = ("Mismatched version of freetype. "
158135
"Test requires '%s', you have '%s'" %
159136
(required_freetype_version, ft2font.__freetype_version__))
160-
return _knownfailureif('indeterminate', msg=reason,
161-
known_exception_class=ImageComparisonFailure)
137+
return pytest.mark.xfail(
138+
not check_freetype_version(required_freetype_version),
139+
reason=reason, raises=ImageComparisonFailure, strict=False)
162140

163141

164142
def remove_ticks_and_titles(figure):
@@ -194,14 +172,11 @@ def _raise_on_image_difference(expected, actual, tol):
194172

195173

196174
def _xfail_if_format_is_uncomparable(extension):
197-
will_fail = extension not in comparable_formats()
198-
if will_fail:
199-
fail_msg = 'Cannot compare %s files on this system' % extension
200-
else:
201-
fail_msg = 'No failure expected'
202-
203-
return _knownfailureif(will_fail, fail_msg,
204-
known_exception_class=ImageComparisonFailure)
175+
import pytest
176+
return pytest.mark.xfail(
177+
extension not in comparable_formats(),
178+
reason='Cannot compare {} files on this system'.format(extension),
179+
raises=ImageComparisonFailure, strict=True)
205180

206181

207182
def _mark_xfail_if_format_is_uncomparable(extension):

0 commit comments

Comments
 (0)