Skip to content
Merged
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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/behavior/31148-ES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Default *style* parameter of ``image_comparison``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The *style* parameter of the `.image_comparison` decorator will become 'mpl20' in
Matplotlib 3.13. Not passing it and relying on the previous default will warn until the
change occurs.
5 changes: 5 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,11 @@ def _init_tests():
ft2font.__freetype_version__,
"" if ft2font.__freetype_build_type__ == 'local' else "not ")

# Generate a shortcut for classic testing style.
from matplotlib.style import _base_library, library
_base_library['_classic_test'] = library['_classic_test'] = RcParams(
_base_library['classic'] | _base_library['_classic_test_patch'])


def _replacer(data, value):
"""
Expand Down
21 changes: 15 additions & 6 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import matplotlib.style
import matplotlib.units
import matplotlib.testing
from matplotlib import _pylab_helpers, cbook, ft2font, pyplot as plt, ticker
from matplotlib import _api, _pylab_helpers, cbook, ft2font, pyplot as plt, ticker
from matplotlib.figure import Figure
from .compare import comparable_formats, compare_images, make_test_filename
from .exceptions import ImageComparisonFailure
Expand Down Expand Up @@ -263,8 +263,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=None):
"""
Compare images generated by the test with those specified in
*baseline_images*, which must correspond, else an `.ImageComparisonFailure`
Expand Down Expand Up @@ -316,9 +315,13 @@ def image_comparison(baseline_images, extensions=None, tol=0,
Optional arguments that are passed to the savefig method.

style : str, dict, or list
The optional style(s) to apply to the image test. The test itself
can also apply additional styles if desired. Defaults to ``["classic",
"_classic_test_patch"]``.
The style(s) to apply to the image test. The test itself can also apply
additional styles if desired.

.. versionchanged:: 3.11
This defaults to ``['classic', '_classic_test_patch']``, but will be
changing to ``'mpl20'`` as of Matplotlib 3.13. A warning is raised if not
explicitly passed.
"""

if baseline_images is not None:
Expand All @@ -342,6 +345,12 @@ def image_comparison(baseline_images, extensions=None, tol=0,
extensions = ['png', 'pdf', 'svg']
if savefig_kwarg is None:
savefig_kwarg = dict() # default no kwargs to savefig
if style is None:
_api.warn_external(
'The default for the style parameter of image_comparsion() will be '
'changing to "mpl20" in Matplotlib 3.13; explicitly pass style to continue '
'working as before and suppress this warning.')
style = ('classic', '_classic_test_patch')
if sys.maxsize <= 2**32:
tol += 0.06
return _pytest_image_comparison(
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/testing/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def image_comparison(
freetype_version: tuple[str, str] | str | None = ...,
remove_text: bool = ...,
savefig_kwarg: dict[str, Any] | None = ...,
style: RcStyleType = ...,
style: RcStyleType | None = ...,
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
def check_figures_equal(
*, extensions: Sequence[str] = ..., tol: float = ...
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ 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_test')
def test_agg_filter():
def smooth1d(x, window_len):
# copied from https://scipy-cookbook.readthedocs.io/
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_arrow_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def draw_arrow(ax, t, r):
fc="b", ec='k'))


@image_comparison(['fancyarrow_test_image.png'],
@image_comparison(['fancyarrow_test_image.png'], style='_classic_test',
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 Down Expand Up @@ -110,8 +110,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_test',
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 @@ -125,8 +125,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_test',
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
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ 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_test')
def test_clipping():
exterior = mpath.Path.unit_rectangle().deepcopy()
exterior.vertices *= 4
Expand Down
Loading
Loading