Skip to content

Commit

Permalink
TST: Increase tolerances for M1 machines
Browse files Browse the repository at this point in the history
These are mostly just single bit changes in antialiasing portions of
diagonal lines.
  • Loading branch information
QuLogic committed Mar 19, 2024
1 parent 53ad914 commit 0fd1b9c
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 67 deletions.
8 changes: 5 additions & 3 deletions lib/matplotlib/tests/test_arrow_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def draw_arrow(ax, t, r):
fc="b", ec='k'))


@image_comparison(['fancyarrow_test_image'])
@image_comparison(['fancyarrow_test_image'],
tol=0.012 if platform.machine() == 'arm64' else 0)
def test_fancyarrow():
# Added 0 to test division by zero error described in issue 3930
r = [0.4, 0.3, 0.2, 0.1, 0]
Expand Down Expand Up @@ -115,7 +116,7 @@ def test_fancyarrow_dash():


@image_comparison(['arrow_styles.png'], style='mpl20', remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.005)
tol=0 if platform.machine() == 'x86_64' else 0.02)
def test_arrow_styles():
styles = mpatches.ArrowStyle.get_styles()

Expand Down Expand Up @@ -147,7 +148,8 @@ def test_arrow_styles():
ax.add_patch(patch)


@image_comparison(['connection_styles.png'], style='mpl20', remove_text=True)
@image_comparison(['connection_styles.png'], style='mpl20', remove_text=True,
tol=0.013 if platform.machine() == 'arm64' else 0)
def test_connection_styles():
styles = mpatches.ConnectionStyle.get_styles()

Expand Down
40 changes: 25 additions & 15 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def test_matshow(fig_test, fig_ref):
'formatter_ticker_003',
'formatter_ticker_004',
'formatter_ticker_005',
])
],
tol=0.031 if platform.machine() == 'arm64' else 0)
def test_formatter_ticker():
import matplotlib.testing.jpl_units as units
units.register()
Expand Down Expand Up @@ -437,7 +438,8 @@ def test_twin_logscale(fig_test, fig_ref, twin):
remove_ticks_and_titles(fig_ref)


@image_comparison(['twin_autoscale.png'])
@image_comparison(['twin_autoscale.png'],
tol=0.009 if platform.machine() == 'arm64' else 0)
def test_twinx_axis_scales():
x = np.array([0, 0.5, 1])
y = 0.5 * x
Expand Down Expand Up @@ -1232,7 +1234,8 @@ def test_fill_betweenx_input(y, x1, x2):
ax.fill_betweenx(y, x1, x2)


@image_comparison(['fill_between_interpolate'], remove_text=True)
@image_comparison(['fill_between_interpolate'], remove_text=True,
tol=0.012 if platform.machine() == 'arm64' else 0)
def test_fill_between_interpolate():
x = np.arange(0.0, 2, 0.02)
y1 = np.sin(2*np.pi*x)
Expand Down Expand Up @@ -1623,7 +1626,7 @@ def test_pcolorauto(fig_test, fig_ref, snap):
ax.pcolormesh(x2, y2, Z, snap=snap)


@image_comparison(['canonical'])
@image_comparison(['canonical'], tol=0.02 if platform.machine() == 'arm64' else 0)
def test_canonical():
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
Expand Down Expand Up @@ -3065,7 +3068,8 @@ def test_log_scales_invalid():
ax.set_ylim(-1, 10)


@image_comparison(['stackplot_test_image', 'stackplot_test_image'])
@image_comparison(['stackplot_test_image', 'stackplot_test_image'],
tol=0.031 if platform.machine() == 'arm64' else 0)
def test_stackplot():
fig = plt.figure()
x = np.linspace(0, 10, 10)
Expand Down Expand Up @@ -4873,7 +4877,8 @@ def test_marker_styles():
marker=marker, markersize=10+y/5, label=marker)


@image_comparison(['rc_markerfill.png'])
@image_comparison(['rc_markerfill.png'],
tol=0.037 if platform.machine() == 'arm64' else 0)
def test_markers_fillstyle_rcparams():
fig, ax = plt.subplots()
x = np.arange(7)
Expand All @@ -4896,7 +4901,7 @@ def test_vertex_markers():


@image_comparison(['vline_hline_zorder', 'errorbar_zorder'],
tol=0 if platform.machine() == 'x86_64' else 0.02)
tol=0 if platform.machine() == 'x86_64' else 0.026)
def test_eb_line_zorder():
x = list(range(10))

Expand Down Expand Up @@ -5455,7 +5460,8 @@ def test_twin_remove(fig_test, fig_ref):
ax_ref.yaxis.tick_left()


@image_comparison(['twin_spines.png'], remove_text=True)
@image_comparison(['twin_spines.png'], remove_text=True,
tol=0.022 if platform.machine() == 'arm64' else 0)
def test_twin_spines():

def make_patch_spines_invisible(ax):
Expand Down Expand Up @@ -5822,7 +5828,7 @@ def test_pie_linewidth_0():
plt.axis('equal')


@image_comparison(['pie_center_radius.png'], style='mpl20', tol=0.005)
@image_comparison(['pie_center_radius.png'], style='mpl20', tol=0.007)
def test_pie_center_radius():
# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
Expand Down Expand Up @@ -6008,7 +6014,8 @@ def test_pie_hatch_multi(fig_test, fig_ref):
[w.set_hatch(hp) for w, hp in zip(wedges, hatch)]


@image_comparison(['set_get_ticklabels.png'])
@image_comparison(['set_get_ticklabels.png'],
tol=0.025 if platform.machine() == 'arm64' else 0)
def test_set_get_ticklabels():
# test issue 2246
fig, ax = plt.subplots(2)
Expand Down Expand Up @@ -6572,7 +6579,8 @@ def test_loglog():
ax.tick_params(length=15, width=2, which='minor')


@image_comparison(["test_loglog_nonpos.png"], remove_text=True, style='mpl20')
@image_comparison(["test_loglog_nonpos.png"], remove_text=True, style='mpl20',
tol=0.029 if platform.machine() == 'arm64' else 0)
def test_loglog_nonpos():
fig, axs = plt.subplots(3, 3)
x = np.arange(1, 11)
Expand Down Expand Up @@ -7498,8 +7506,8 @@ def test_scatter_empty_data():
plt.scatter([], [], s=[], c=[])


@image_comparison(['annotate_across_transforms.png'],
style='mpl20', remove_text=True)
@image_comparison(['annotate_across_transforms.png'], style='mpl20', remove_text=True,
tol=0.025 if platform.machine() == 'arm64' else 0)
def test_annotate_across_transforms():
x = np.linspace(0, 10, 200)
y = np.exp(-x) * np.sin(x)
Expand Down Expand Up @@ -7529,7 +7537,8 @@ def inverted(self):
return _Translation(-self.dx)


@image_comparison(['secondary_xy.png'], style='mpl20')
@image_comparison(['secondary_xy.png'], style='mpl20',
tol=0.027 if platform.machine() == 'arm64' else 0)
def test_secondary_xy():
fig, axs = plt.subplots(1, 2, figsize=(10, 5), constrained_layout=True)

Expand Down Expand Up @@ -8785,7 +8794,8 @@ def test_zorder_and_explicit_rasterization():
fig.savefig(b, format='pdf')


@image_comparison(["preset_clip_paths.png"], remove_text=True, style="mpl20")
@image_comparison(["preset_clip_paths.png"], remove_text=True, style="mpl20",
tol=0.027 if platform.machine() == "arm64" else 0)
def test_preset_clip_paths():
fig, ax = plt.subplots()

Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_bbox_tight.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from io import BytesIO
import platform

import numpy as np

Expand Down Expand Up @@ -43,7 +44,8 @@ def test_bbox_inches_tight():


@image_comparison(['bbox_inches_tight_suptile_legend'],
savefig_kwarg={'bbox_inches': 'tight'})
savefig_kwarg={'bbox_inches': 'tight'},
tol=0.02 if platform.machine() == 'arm64' else 0)
def test_bbox_inches_tight_suptile_legend():
plt.plot(np.arange(10), label='a straight line')
plt.legend(bbox_to_anchor=(0.9, 1), loc='upper left')
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
import io
import itertools
import platform
import re
from types import SimpleNamespace

Expand Down Expand Up @@ -388,7 +389,8 @@ def test_barb_limits():
decimal=1)


@image_comparison(['EllipseCollection_test_image.png'], remove_text=True)
@image_comparison(['EllipseCollection_test_image.png'], remove_text=True,
tol=0.021 if platform.machine() == 'arm64' else 0)
def test_EllipseCollection():
# Test basic functionality
fig, ax = plt.subplots()
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,8 @@ def test_colorbar_single_ax_panchor_east(constrained):
assert ax.get_anchor() == 'E'


@image_comparison(
['contour_colorbar.png'], remove_text=True,
tol=0.01 if platform.machine() in ('aarch64', 'ppc64le', 's390x') else 0)
@image_comparison(['contour_colorbar.png'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.054)
def test_contour_colorbar():
fig, ax = plt.subplots(figsize=(4, 2))
data = np.arange(1200).reshape(30, 40) - 500
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import gc
import platform

import numpy as np
import pytest

Expand Down Expand Up @@ -195,7 +197,8 @@ def test_constrained_layout9():
fig.suptitle('Test Suptitle', fontsize=28)


@image_comparison(['constrained_layout10.png'])
@image_comparison(['constrained_layout10.png'],
tol=0.032 if platform.machine() == 'arm64' else 0)
def test_constrained_layout10():
"""Test for handling legend outside axis"""
fig, axs = plt.subplots(2, 2, layout="constrained")
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def test_contour_label_with_disconnected_segments(split_collections):


@pytest.mark.parametrize("split_collections", [False, True])
@image_comparison(['contour_manual_colors_and_levels.png'], remove_text=True)
@image_comparison(['contour_manual_colors_and_levels.png'], remove_text=True,
tol=0.018 if platform.machine() == 'arm64' else 0)
def test_given_colors_levels_and_extends(split_collections):
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def test_clf_keyword():
assert [t.get_text() for t in fig2.texts] == []


@image_comparison(['figure_today'])
@image_comparison(['figure_today'],
tol=0.015 if platform.machine() == 'arm64' else 0)
def test_figure():
# named figure support
fig = plt.figure('today')
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ def test_nonuniform_and_pcolor():

@image_comparison(
['rgba_antialias.png'], style='mpl20', remove_text=True,
tol=0.007 if platform.machine() in ('aarch64', 'ppc64le', 's390x') else 0)
tol=0 if platform.machine() == 'x86_64' else 0.007)
def test_rgba_antialias():
fig, axs = plt.subplots(2, 2, figsize=(3.5, 3.5), sharex=False,
sharey=False, constrained_layout=True)
Expand Down
19 changes: 11 additions & 8 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def test_legend_label_with_leading_underscore():
assert len(legend.legend_handles) == 0


@image_comparison(['legend_labels_first.png'], remove_text=True)
@image_comparison(['legend_labels_first.png'], remove_text=True,
tol=0.013 if platform.machine() == 'arm64' else 0)
def test_labels_first():
# test labels to left of markers
fig, ax = plt.subplots()
Expand All @@ -161,7 +162,8 @@ def test_labels_first():
ax.legend(loc='best', markerfirst=False)


@image_comparison(['legend_multiple_keys.png'], remove_text=True)
@image_comparison(['legend_multiple_keys.png'], remove_text=True,
tol=0.013 if platform.machine() == 'arm64' else 0)
def test_multiple_keys():
# test legend entries with multiple keys
fig, ax = plt.subplots()
Expand All @@ -175,7 +177,7 @@ def test_multiple_keys():


@image_comparison(['rgba_alpha.png'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.01)
tol=0 if platform.machine() == 'x86_64' else 0.03)
def test_alpha_rgba():
fig, ax = plt.subplots()
ax.plot(range(10), lw=5)
Expand All @@ -184,7 +186,7 @@ def test_alpha_rgba():


@image_comparison(['rcparam_alpha.png'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.01)
tol=0 if platform.machine() == 'x86_64' else 0.03)
def test_alpha_rcparam():
fig, ax = plt.subplots()
ax.plot(range(10), lw=5)
Expand Down Expand Up @@ -212,7 +214,7 @@ def test_fancy():


@image_comparison(['framealpha'], remove_text=True,
tol=0 if platform.machine() == 'x86_64' else 0.02)
tol=0 if platform.machine() == 'x86_64' else 0.024)
def test_framealpha():
x = np.linspace(1, 100, 100)
y = x
Expand Down Expand Up @@ -523,7 +525,8 @@ def test_figure_legend_outside():
legbb[nn])


@image_comparison(['legend_stackplot.png'])
@image_comparison(['legend_stackplot.png'],
tol=0.031 if platform.machine() == 'arm64' else 0)
def test_legend_stackplot():
"""Test legend for PolyCollection using stackplot."""
# related to #1341, #1943, and PR #3303
Expand Down Expand Up @@ -658,8 +661,8 @@ def test_empty_bar_chart_with_legend():
plt.legend()


@image_comparison(['shadow_argument_types.png'], remove_text=True,
style='mpl20')
@image_comparison(['shadow_argument_types.png'], remove_text=True, style='mpl20',
tol=0.028 if platform.machine() == 'arm64' else 0)
def test_shadow_argument_types():
# Test that different arguments for shadow work as expected
fig, ax = plt.subplots()
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_invalid_line_data():
line.set_ydata(0)


@image_comparison(['line_dashes'], remove_text=True, tol=0.002)
@image_comparison(['line_dashes'], remove_text=True, tol=0.003)
def test_line_dashes():
# Tolerance introduced after reordering of floating-point operations
# Remove when regenerating the images
Expand Down Expand Up @@ -139,7 +139,8 @@ def test_valid_linestyles():
line.set_linestyle('aardvark')


@image_comparison(['drawstyle_variants.png'], remove_text=True)
@image_comparison(['drawstyle_variants.png'], remove_text=True,
tol=0.03 if platform.machine() == 'arm64' else 0)
def test_drawstyle_variants():
fig, axs = plt.subplots(6)
dss = ["default", "steps-mid", "steps-pre", "steps-post", "steps", None]
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Tests specific to the patches module.
"""
import platform

import numpy as np
from numpy.testing import assert_almost_equal, assert_array_equal
import pytest
Expand All @@ -15,9 +17,6 @@
collections as mcollections, colors as mcolors, patches as mpatches,
path as mpath, transforms as mtransforms, rcParams)

import sys
on_win = (sys.platform == 'win32')


def test_Polygon_close():
#: GitHub issue #1018 identified a bug in the Polygon handling
Expand Down Expand Up @@ -438,8 +437,8 @@ def test_wedge_movement():
assert getattr(w, attr) == new_v


# png needs tol>=0.06, pdf tol>=1.617
@image_comparison(['wedge_range'], remove_text=True, tol=1.65 if on_win else 0)
@image_comparison(['wedge_range'], remove_text=True,
tol=0.009 if platform.machine() == 'arm64' else 0)
def test_wedge_range():
ax = plt.axes()

Expand Down Expand Up @@ -564,7 +563,8 @@ def test_units_rectangle():
ax.set_ylim([5*U.km, 9*U.km])


@image_comparison(['connection_patch.png'], style='mpl20', remove_text=True)
@image_comparison(['connection_patch.png'], style='mpl20', remove_text=True,
tol=0.024 if platform.machine() == 'arm64' else 0)
def test_connection_patch():
fig, (ax1, ax2) = plt.subplots(1, 2)

Expand Down
Loading

0 comments on commit 0fd1b9c

Please sign in to comment.