26
26
from matplotlib import ft2font
27
27
from matplotlib .testing .compare import comparable_formats , compare_images , \
28
28
make_test_filename
29
- from . import copy_metadata , is_called_from_pytest , xfail
29
+ from . import _copy_metadata , is_called_from_pytest
30
30
from .exceptions import ImageComparisonFailure
31
31
32
32
33
- def skipif (condition , * args , ** kwargs ):
34
- """Skip the given test function if eval(condition) results in a True
35
- value.
36
-
37
- Optionally specify a reason for better reporting.
38
- """
39
- if is_called_from_pytest ():
40
- import pytest
41
- return pytest .mark .skipif (condition , * args , ** kwargs )
42
- else :
43
- from ._nose .decorators import skipif
44
- return skipif (condition , * args , ** kwargs )
45
-
46
-
47
- def knownfailureif (fail_condition , msg = None , known_exception_class = None ):
33
+ def _knownfailureif (fail_condition , msg = None , known_exception_class = None ):
48
34
"""
49
35
50
36
Assume a will fail if *fail_condition* is True. *fail_condition*
@@ -69,6 +55,12 @@ def knownfailureif(fail_condition, msg=None, known_exception_class=None):
69
55
return knownfailureif (fail_condition , msg , known_exception_class )
70
56
71
57
58
+ @cbook .deprecated ('2.1' ,
59
+ alternative = 'pytest.xfail or import the plugin' )
60
+ def knownfailureif (fail_condition , msg = None , known_exception_class = None ):
61
+ _knownfailureif (fail_condition , msg , known_exception_class )
62
+
63
+
72
64
def _do_cleanup (original_units_registry , original_settings ):
73
65
plt .close ('all' )
74
66
@@ -175,15 +167,15 @@ def check_freetype_version(ver):
175
167
return found >= ver [0 ] and found <= ver [1 ]
176
168
177
169
178
- def checked_on_freetype_version (required_freetype_version ):
170
+ def _checked_on_freetype_version (required_freetype_version ):
179
171
if check_freetype_version (required_freetype_version ):
180
172
return lambda f : f
181
173
182
174
reason = ("Mismatched version of freetype. "
183
175
"Test requires '%s', you have '%s'" %
184
176
(required_freetype_version , ft2font .__freetype_version__ ))
185
- return knownfailureif ('indeterminate' , msg = reason ,
186
- known_exception_class = ImageComparisonFailure )
177
+ return _knownfailureif ('indeterminate' , msg = reason ,
178
+ known_exception_class = ImageComparisonFailure )
187
179
188
180
189
181
def remove_ticks_and_titles (figure ):
@@ -202,7 +194,7 @@ def remove_ticks_and_titles(figure):
202
194
pass
203
195
204
196
205
- def raise_on_image_difference (expected , actual , tol ):
197
+ def _raise_on_image_difference (expected , actual , tol ):
206
198
__tracebackhide__ = True
207
199
208
200
err = compare_images (expected , actual , tol , in_decorator = True )
@@ -216,18 +208,18 @@ def raise_on_image_difference(expected, actual, tol):
216
208
'(RMS %(rms).3f)' % err )
217
209
218
210
219
- def xfail_if_format_is_uncomparable (extension ):
211
+ def _xfail_if_format_is_uncomparable (extension ):
220
212
will_fail = extension not in comparable_formats ()
221
213
if will_fail :
222
214
fail_msg = 'Cannot compare %s files on this system' % extension
223
215
else :
224
216
fail_msg = 'No failure expected'
225
217
226
- return knownfailureif (will_fail , fail_msg ,
227
- known_exception_class = ImageComparisonFailure )
218
+ return _knownfailureif (will_fail , fail_msg ,
219
+ known_exception_class = ImageComparisonFailure )
228
220
229
221
230
- def mark_xfail_if_format_is_uncomparable (extension ):
222
+ def _mark_xfail_if_format_is_uncomparable (extension ):
231
223
will_fail = extension not in comparable_formats ()
232
224
if will_fail :
233
225
fail_msg = 'Cannot compare %s files on this system' % extension
@@ -284,9 +276,15 @@ def copy_baseline(self, baseline, extension):
284
276
if os .path .exists (orig_expected_fname ):
285
277
shutil .copyfile (orig_expected_fname , expected_fname )
286
278
else :
287
- xfail ("Do not have baseline image {0} because this "
288
- "file does not exist: {1}" .format (expected_fname ,
289
- orig_expected_fname ))
279
+ reason = ("Do not have baseline image {0} because this "
280
+ "file does not exist: {1}" .format (expected_fname ,
281
+ orig_expected_fname ))
282
+ if is_called_from_pytest ():
283
+ import pytest
284
+ pytest .xfail (reason )
285
+ else :
286
+ from ._nose import knownfail
287
+ knownfail (reason )
290
288
return expected_fname
291
289
292
290
def compare (self , idx , baseline , extension ):
@@ -306,12 +304,12 @@ def compare(self, idx, baseline, extension):
306
304
fig .savefig (actual_fname , ** kwargs )
307
305
308
306
expected_fname = self .copy_baseline (baseline , extension )
309
- raise_on_image_difference (expected_fname , actual_fname , self .tol )
307
+ _raise_on_image_difference (expected_fname , actual_fname , self .tol )
310
308
311
309
def nose_runner (self ):
312
310
func = self .compare
313
- func = checked_on_freetype_version (self .freetype_version )(func )
314
- funcs = {extension : xfail_if_format_is_uncomparable (extension )(func )
311
+ func = _checked_on_freetype_version (self .freetype_version )(func )
312
+ funcs = {extension : _xfail_if_format_is_uncomparable (extension )(func )
315
313
for extension in self .extensions }
316
314
for idx , baseline in enumerate (self .baseline_images ):
317
315
for extension in self .extensions :
@@ -320,19 +318,20 @@ def nose_runner(self):
320
318
def pytest_runner (self ):
321
319
from pytest import mark
322
320
323
- extensions = map (mark_xfail_if_format_is_uncomparable , self .extensions )
321
+ extensions = map (_mark_xfail_if_format_is_uncomparable ,
322
+ self .extensions )
324
323
325
324
if len (set (self .baseline_images )) == len (self .baseline_images ):
326
325
@mark .parametrize ("extension" , extensions )
327
326
@mark .parametrize ("idx,baseline" , enumerate (self .baseline_images ))
328
- @checked_on_freetype_version (self .freetype_version )
327
+ @_checked_on_freetype_version (self .freetype_version )
329
328
def wrapper (idx , baseline , extension ):
330
329
__tracebackhide__ = True
331
330
self .compare (idx , baseline , extension )
332
331
else :
333
332
# Some baseline images are repeated, so run this in serial.
334
333
@mark .parametrize ("extension" , extensions )
335
- @checked_on_freetype_version (self .freetype_version )
334
+ @_checked_on_freetype_version (self .freetype_version )
336
335
def wrapper (extension ):
337
336
__tracebackhide__ = True
338
337
for idx , baseline in enumerate (self .baseline_images ):
@@ -348,7 +347,7 @@ def wrapper(extension):
348
347
def __call__ (self , func ):
349
348
self .delayed_init (func )
350
349
if is_called_from_pytest ():
351
- return copy_metadata (func , self .pytest_runner ())
350
+ return _copy_metadata (func , self .pytest_runner ())
352
351
else :
353
352
import nose .tools
354
353
@@ -361,7 +360,7 @@ def runner_wrapper():
361
360
# nose bug...
362
361
self .teardown ()
363
362
364
- return copy_metadata (func , runner_wrapper )
363
+ return _copy_metadata (func , runner_wrapper )
365
364
366
365
367
366
def image_comparison (baseline_images = None , extensions = None , tol = 0 ,
@@ -497,7 +496,7 @@ def backend_switcher(*args, **kwargs):
497
496
plt .switch_backend (prev_backend )
498
497
return result
499
498
500
- return copy_metadata (func , backend_switcher )
499
+ return _copy_metadata (func , backend_switcher )
501
500
return switch_backend_decorator
502
501
503
502
@@ -516,6 +515,7 @@ def skip_if_command_unavailable(cmd):
516
515
try :
517
516
check_output (cmd )
518
517
except :
519
- return skipif (True , reason = 'missing command: %s' % cmd [0 ])
518
+ import pytest
519
+ return pytest .mark .skip (reason = 'missing command: %s' % cmd [0 ])
520
520
521
521
return lambda f : f
0 commit comments