Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/devel/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ tests it::
fig, ax = plt.subplots()
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)

If you wish to compare only a single extension, then that may be included in the
baseline image name as a shortcut::

@image_comparison(baseline_images=['line_dashes.png'], remove_text=True,
style='mpl20')
def test_line_dashes():
fig, ax = plt.subplots()
ax.plot(range(10), linestyle=(0, (3, 3)), lw=5)

The first time this test is run, there will be no baseline image to compare
against, so the test will fail. Copy the output images (in this case
:file:`result_images/test_lines/test_line_dashes.png`) to the correct
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ def wrapper(*args, extension, request, **kwargs):
def image_comparison(baseline_images, extensions=None, tol=0,
freetype_version=None, remove_text=False,
savefig_kwarg=None,
# Default of mpl_test_settings fixture and cleanup too.
style=("classic", "_classic_test_patch")):
*, style):
"""
Compare images generated by the test with those specified in
*baseline_images*, which must correspond, else an `.ImageComparisonFailure`
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/testing/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def image_comparison(
freetype_version: tuple[str, str] | str | None = ...,
remove_text: bool = ...,
savefig_kwarg: dict[str, Any] | None = ...,
style: RcStyleType = ...,
*,
style: RcStyleType,
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
def check_figures_equal(
*, extensions: Sequence[str] = ..., tol: float = ...
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def test_long_path():
fig.savefig(buff, format='png')


@image_comparison(['agg_filter.png'], remove_text=True)
@image_comparison(['agg_filter.png'], remove_text=True,
style=('classic', '_classic_test_patch'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a new style _classic_test? This feels overly verbose.

def test_agg_filter():
def smooth1d(x, window_len):
# copied from https://scipy-cookbook.readthedocs.io/
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_agg_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


@image_comparison(baseline_images=['agg_filter_alpha'],
extensions=['gif', 'png', 'pdf'])
extensions=['gif', 'png', 'pdf'],
style=('classic', '_classic_test_patch'))
def test_agg_filter_alpha():
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False
Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/tests/test_arrow_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def draw_arrow(ax, t, r):


@image_comparison(['fancyarrow_test_image.png'],
style=('classic', '_classic_test_patch'),
tol=0 if platform.machine() == 'x86_64' else 0.012)
def test_fancyarrow():
# Added 0 to test division by zero error described in issue 3930
Expand All @@ -28,7 +29,7 @@ def test_fancyarrow():
ax.tick_params(labelleft=False, labelbottom=False)


@image_comparison(['boxarrow_test_image.png'])
@image_comparison(['boxarrow_test_image.png'], style=('classic', '_classic_test_patch'))
def test_boxarrow():

styles = mpatches.BoxStyle.get_styles()
Expand Down Expand Up @@ -68,8 +69,8 @@ def __prepare_fancyarrow_dpi_cor_test():


@image_comparison(['fancyarrow_dpi_cor_100dpi.png'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.02,
savefig_kwarg=dict(dpi=100))
savefig_kwarg=dict(dpi=100), style=('classic', '_classic_test_patch'),
tol=0 if platform.machine() == 'x86_64' else 0.02)
def test_fancyarrow_dpi_cor_100dpi():
"""
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
Expand All @@ -83,8 +84,8 @@ def test_fancyarrow_dpi_cor_100dpi():


@image_comparison(['fancyarrow_dpi_cor_200dpi.png'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.02,
savefig_kwarg=dict(dpi=200))
savefig_kwarg=dict(dpi=200), style=('classic', '_classic_test_patch'),
tol=0 if platform.machine() == 'x86_64' else 0.02)
def test_fancyarrow_dpi_cor_200dpi():
"""
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_collection_transform_of_none():
assert isinstance(c.get_offset_transform(), mtransforms.IdentityTransform)


@image_comparison(["clip_path_clipping"], remove_text=True)
@image_comparison(["clip_path_clipping"], remove_text=True,
style=('classic', '_classic_test_patch'))
def test_clipping():
exterior = mpath.Path.unit_rectangle().deepcopy()
exterior.vertices *= 4
Expand Down
Loading
Loading