@@ -234,6 +234,12 @@ def _mark_xfail_if_format_is_uncomparable(extension):
234234
235235
236236class _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
284290class 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():
339354def _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