Skip to content

Commit a18b014

Browse files
committed
TST: Use explicit style in all image_comparison calls
This makes it so that future tests *must* use the new style (or explicitly opt in to the old), and in the future, we may return to a default of that one instead. As a shortcut, the `_classic_test` style is generated from `classic` and `_classic_test_patch` at test startup. Fixes #24716
1 parent cb63559 commit a18b014

40 files changed

+359
-299
lines changed

lib/matplotlib/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,11 @@ def _init_tests():
13481348
ft2font.__freetype_version__,
13491349
"" if ft2font.__freetype_build_type__ == 'local' else "not ")
13501350

1351+
# Generate a shortcut for classic testing style.
1352+
from matplotlib.style import _base_library, library
1353+
_base_library['_classic_test'] = library['_classic_test'] = (
1354+
_base_library['classic'] | _base_library['_classic_test_patch'])
1355+
13511356

13521357
def _replacer(data, value):
13531358
"""

lib/matplotlib/testing/decorators.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ def wrapper(*args, extension, request, **kwargs):
260260
def image_comparison(baseline_images, extensions=None, tol=0,
261261
freetype_version=None, remove_text=False,
262262
savefig_kwarg=None,
263-
# Default of mpl_test_settings fixture and cleanup too.
264-
style=("classic", "_classic_test_patch")):
263+
*, style):
265264
"""
266265
Compare images generated by the test with those specified in
267266
*baseline_images*, which must correspond, else an `.ImageComparisonFailure`

lib/matplotlib/testing/decorators.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def image_comparison(
1717
freetype_version: tuple[str, str] | str | None = ...,
1818
remove_text: bool = ...,
1919
savefig_kwarg: dict[str, Any] | None = ...,
20-
style: RcStyleType = ...,
20+
*,
21+
style: RcStyleType,
2122
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
2223
def check_figures_equal(
2324
*, extensions: Sequence[str] = ..., tol: float = ...

lib/matplotlib/tests/test_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_long_path():
9292
fig.savefig(buff, format='png')
9393

9494

95-
@image_comparison(['agg_filter.png'], remove_text=True)
95+
@image_comparison(['agg_filter.png'], remove_text=True, style='_classic_test')
9696
def test_agg_filter():
9797
def smooth1d(x, window_len):
9898
# copied from https://scipy-cookbook.readthedocs.io/

lib/matplotlib/tests/test_agg_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@image_comparison(baseline_images=['agg_filter_alpha'],
8-
extensions=['gif', 'png', 'pdf'])
8+
extensions=['gif', 'png', 'pdf'], style='_classic_test')
99
def test_agg_filter_alpha():
1010
# Remove this line when this test image is regenerated.
1111
plt.rcParams['pcolormesh.snap'] = False

lib/matplotlib/tests/test_arrow_patches.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def draw_arrow(ax, t, r):
1111
fc="b", ec='k'))
1212

1313

14-
@image_comparison(['fancyarrow_test_image.png'],
14+
@image_comparison(['fancyarrow_test_image.png'], style='_classic_test',
1515
tol=0 if platform.machine() == 'x86_64' else 0.012)
1616
def test_fancyarrow():
1717
# Added 0 to test division by zero error described in issue 3930
@@ -28,7 +28,7 @@ def test_fancyarrow():
2828
ax.tick_params(labelleft=False, labelbottom=False)
2929

3030

31-
@image_comparison(['boxarrow_test_image.png'])
31+
@image_comparison(['boxarrow_test_image.png'], style='_classic_test')
3232
def test_boxarrow():
3333

3434
styles = mpatches.BoxStyle.get_styles()
@@ -68,8 +68,8 @@ def __prepare_fancyarrow_dpi_cor_test():
6868

6969

7070
@image_comparison(['fancyarrow_dpi_cor_100dpi.png'], remove_text=True,
71-
tol=0 if platform.machine() == 'x86_64' else 0.02,
72-
savefig_kwarg=dict(dpi=100))
71+
savefig_kwarg=dict(dpi=100), style='_classic_test',
72+
tol=0 if platform.machine() == 'x86_64' else 0.02)
7373
def test_fancyarrow_dpi_cor_100dpi():
7474
"""
7575
Check the export of a FancyArrowPatch @ 100 DPI. FancyArrowPatch is
@@ -83,8 +83,8 @@ def test_fancyarrow_dpi_cor_100dpi():
8383

8484

8585
@image_comparison(['fancyarrow_dpi_cor_200dpi.png'], remove_text=True,
86-
tol=0 if platform.machine() == 'x86_64' else 0.02,
87-
savefig_kwarg=dict(dpi=200))
86+
savefig_kwarg=dict(dpi=200), style='_classic_test',
87+
tol=0 if platform.machine() == 'x86_64' else 0.02)
8888
def test_fancyarrow_dpi_cor_200dpi():
8989
"""
9090
As test_fancyarrow_dpi_cor_100dpi, but exports @ 200 DPI. The relative size

lib/matplotlib/tests/test_artist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_collection_transform_of_none():
9696
assert isinstance(c.get_offset_transform(), mtransforms.IdentityTransform)
9797

9898

99-
@image_comparison(["clip_path_clipping"], remove_text=True)
99+
@image_comparison(["clip_path_clipping"], remove_text=True, style='_classic_test')
100100
def test_clipping():
101101
exterior = mpath.Path.unit_rectangle().deepcopy()
102102
exterior.vertices *= 4

0 commit comments

Comments
 (0)