diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index cb6812d7e42a..8ddb604730c2 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -336,6 +336,9 @@ def image_comparison(baseline_images, extensions=None, tol=0, tol : float, default: 0 The RMS threshold above which the test is considered failed. + Due to expected small differences in floating-point calculations, on + 32-bit systems an additional 0.06 is added to this threshold. + freetype_version : str or tuple The expected freetype version or range of versions for this test to pass. @@ -378,6 +381,8 @@ 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 sys.maxsize <= 2**32: + tol += 0.06 return _pytest_image_comparison( baseline_images=baseline_images, extensions=extensions, tol=tol, freetype_version=freetype_version, remove_text=remove_text, diff --git a/lib/matplotlib/tests/test_arrow_patches.py b/lib/matplotlib/tests/test_arrow_patches.py index 2218a2e7f429..cca505ab908b 100644 --- a/lib/matplotlib/tests/test_arrow_patches.py +++ b/lib/matplotlib/tests/test_arrow_patches.py @@ -67,7 +67,7 @@ def __prepare_fancyarrow_dpi_cor_test(): @image_comparison(['fancyarrow_dpi_cor_100dpi.png'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0), + tol=0 if platform.machine() == 'x86_64' else 0.02, savefig_kwarg=dict(dpi=100)) def test_fancyarrow_dpi_cor_100dpi(): """ @@ -82,7 +82,7 @@ def test_fancyarrow_dpi_cor_100dpi(): @image_comparison(['fancyarrow_dpi_cor_200dpi.png'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0), + tol=0 if platform.machine() == 'x86_64' else 0.02, savefig_kwarg=dict(dpi=200)) def test_fancyarrow_dpi_cor_200dpi(): """ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index ae144b607afa..5ec06afc3b4c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3713,7 +3713,7 @@ def test_vertex_markers(): @image_comparison(['vline_hline_zorder', 'errorbar_zorder'], - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.02) def test_eb_line_zorder(): x = list(range(10)) diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index 2d125ad29749..702cc6c35870 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -8,7 +8,6 @@ import numpy as np import pytest -import platform import matplotlib as mpl import matplotlib.pyplot as plt @@ -179,10 +178,7 @@ def test_pathclip(): # test mixed mode rendering @needs_xelatex @pytest.mark.backend('pgf') -@image_comparison(['pgf_mixedmode.pdf'], style='default', - tol={'aarch64': 1.086, 'x86_64': 1.086}.get( - platform.machine(), 0.0 - )) +@image_comparison(['pgf_mixedmode.pdf'], style='default') def test_mixedmode(): rc_xelatex = {'font.family': 'serif', 'pgf.rcfonts': False} diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index 77f6e1884813..d457fe372f42 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -1,5 +1,4 @@ import io -import platform from types import SimpleNamespace import numpy as np @@ -334,8 +333,7 @@ def test_barb_limits(): decimal=1) -@image_comparison(['EllipseCollection_test_image.png'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) +@image_comparison(['EllipseCollection_test_image.png'], remove_text=True) def test_EllipseCollection(): # Test basic functionality fig, ax = plt.subplots() diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index 446d9f3a7ff7..958db50e997b 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -1,4 +1,5 @@ import datetime +import platform import re import numpy as np @@ -189,7 +190,8 @@ def test_contour_datetime_axis(): @image_comparison(['contour_test_label_transforms.png'], - remove_text=True, style='mpl20') + remove_text=True, style='mpl20', + tol=0 if platform.machine() == 'x86_64' else 0.08) def test_labels(): # Adapted from pylab_examples example code: contour_demo.py # see issues #2475, #2843, and #2818 for explanation diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index ce46e4f1eed9..dc04a869ce7b 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -22,7 +22,7 @@ @image_comparison(['figure_align_labels'], - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_align_labels(): fig = plt.figure(tight_layout=True) gs = gridspec.GridSpec(3, 3) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index b5fd6e6fe938..fc4ad30badb8 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -861,7 +861,7 @@ def test_imshow_endianess(): @image_comparison(['imshow_masked_interpolation'], - tol={'aarch64': 0.02}.get(platform.machine(), 0.0), + tol=0 if platform.machine() == 'x86_64' else 0.01, remove_text=True, style='mpl20') def test_imshow_masked_interpolation(): diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index df09a884b42c..8e9c0771fb3d 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -105,7 +105,7 @@ def test_multiple_keys(): @image_comparison(['rgba_alpha.png'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_alpha_rgba(): fig, ax = plt.subplots(1, 1) ax.plot(range(10), lw=5) @@ -114,7 +114,7 @@ def test_alpha_rgba(): @image_comparison(['rcparam_alpha.png'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_alpha_rcparam(): fig, ax = plt.subplots(1, 1) ax.plot(range(10), lw=5) @@ -140,7 +140,7 @@ def test_fancy(): @image_comparison(['framealpha'], remove_text=True, - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.02) def test_framealpha(): x = np.linspace(1, 100, 100) y = x diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index d8c54e770757..77b6ae3145be 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -115,7 +115,7 @@ def test_SimplePatchShadow_offset(): assert pe._offset == (4, 5) -@image_comparison(['collection'], tol=0.02, style='mpl20') +@image_comparison(['collection'], tol=0.03, style='mpl20') def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y) diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 6a78526b5a64..82bf4d8e8285 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -41,7 +41,7 @@ def test_simple(): @image_comparison(['multi_pickle.png'], remove_text=True, style='mpl20', - tol={'aarch64': 0.082}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.082) def test_complete(): fig = plt.figure('Figure with a label?', figsize=(10, 6)) diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index 100954ac32a7..da9a77c82502 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -1,3 +1,5 @@ +import platform + import numpy as np from numpy.testing import assert_allclose import pytest @@ -7,7 +9,8 @@ from matplotlib.testing.decorators import image_comparison, check_figures_equal -@image_comparison(['polar_axes'], style='default') +@image_comparison(['polar_axes'], style='default', + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_polar_annotations(): # You can specify the xypoint and the xytext in different positions and # coordinate systems, and optionally turn on a connecting line and mark the diff --git a/lib/matplotlib/tests/test_streamplot.py b/lib/matplotlib/tests/test_streamplot.py index d2218f6f288d..2e795c2a3142 100644 --- a/lib/matplotlib/tests/test_streamplot.py +++ b/lib/matplotlib/tests/test_streamplot.py @@ -1,5 +1,4 @@ import sys -import platform import numpy as np from numpy.testing import assert_array_almost_equal @@ -48,8 +47,7 @@ def test_colormap(): plt.colorbar() -@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20', - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) +@image_comparison(['streamplot_linewidth'], remove_text=True, style='mpl20') def test_linewidth(): X, Y, U, V = velocity_field() speed = np.hypot(U, V) diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index 25396ff0ffe6..252136b4dfb4 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -74,7 +74,7 @@ def default_units(value, axis): # Tests that the conversion machinery works properly for classes that # work as a facade over numpy arrays (like pint) @image_comparison(['plot_pint.png'], remove_text=False, style='mpl20', - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_numpy_facade(quantity_converter): # use former defaults to match existing baseline image plt.rcParams['axes.formatter.limits'] = -7, 7 @@ -101,7 +101,7 @@ def test_numpy_facade(quantity_converter): # Tests gh-8908 @image_comparison(['plot_masked_units.png'], remove_text=True, style='mpl20', - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_plot_masked_units(): data = np.linspace(-5, 5) data_masked = np.ma.array(data, mask=(data > -2) & (data < 2)) diff --git a/lib/mpl_toolkits/tests/test_axes_grid1.py b/lib/mpl_toolkits/tests/test_axes_grid1.py index 0aa2c76002b7..96830441e8da 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/tests/test_axes_grid1.py @@ -331,7 +331,7 @@ def test_zooming_with_inverted_axes(): @image_comparison(['anchored_direction_arrows.png'], - tol={'aarch64': 0.02}.get(platform.machine(), 0.0)) + tol=0 if platform.machine() == 'x86_64' else 0.01) def test_anchored_direction_arrows(): fig, ax = plt.subplots() ax.imshow(np.zeros((10, 10)), interpolation='nearest') diff --git a/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py b/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py index bed21a64053c..05534869a09b 100644 --- a/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py +++ b/lib/mpl_toolkits/tests/test_axisartist_grid_helper_curvelinear.py @@ -17,7 +17,7 @@ @image_comparison(['custom_transform.png'], style='default', - tol={'aarch64': 0.034}.get(platform.machine(), 0.03)) + tol=0.03 if platform.machine() == 'x86_64' else 0.034) def test_custom_transform(): class MyTransform(Transform): input_dims = output_dims = 2