@@ -234,6 +234,12 @@ def _mark_xfail_if_format_is_uncomparable(extension):
234
234
235
235
236
236
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
+ """
237
243
def __init__ (self , tol , remove_text , savefig_kwargs ):
238
244
self .func = self .baseline_dir = self .result_dir = None
239
245
self .tol = tol
@@ -282,6 +288,15 @@ def compare(self, idx, baseline, extension):
282
288
283
289
284
290
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
+ """
285
300
def __init__ (self , baseline_images , extensions , tol ,
286
301
freetype_version , remove_text , savefig_kwargs , style ):
287
302
_ImageComparisonBase .__init__ (self , tol , remove_text , savefig_kwargs )
@@ -339,14 +354,24 @@ def runner_wrapper():
339
354
def _pytest_image_comparison (baseline_images , extensions , tol ,
340
355
freetype_version , remove_text , savefig_kwargs ,
341
356
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
+ """
342
365
import pytest
343
366
344
367
extensions = map (_mark_xfail_if_format_is_uncomparable , extensions )
345
368
346
369
def decorator (func ):
370
+ # Parameter indirection; see docstring above and comment below.
347
371
@pytest .mark .usefixtures ('mpl_image_comparison_parameters' )
348
372
@pytest .mark .parametrize ('extension' , extensions )
349
373
@pytest .mark .baseline_images (baseline_images )
374
+ # END Parameter indirection.
350
375
@pytest .mark .style (style )
351
376
@_checked_on_freetype_version (freetype_version )
352
377
@functools .wraps (func )
@@ -358,6 +383,7 @@ def wrapper(*args, **kwargs):
358
383
matplotlib .testing .set_font_settings_for_testing ()
359
384
func (* args , ** kwargs )
360
385
386
+ # Parameter indirection:
361
387
# This is hacked on via the mpl_image_comparison_parameters fixture
362
388
# so that we don't need to modify the function's real signature for
363
389
# any parametrization. Modifying the signature is very very tricky
0 commit comments