Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TST: Set explicit styles for image tests #24709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Draft
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
4 changes: 3 additions & 1 deletion 4 lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def test_long_path():
fig.savefig(buff, format='png')


@image_comparison(['agg_filter.png'], remove_text=True)
# # Update style when regenerating the test image
@image_comparison(['agg_filter.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
Copy link
Member

@timhoffm timhoffm Dec 13, 2022

Choose a reason for hiding this comment

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

Having this baseline + patch style combination is a bit bulky given that we write it all over the tests. I suggest to create a _classic_test style that hard-coded merges both.

Copy link
Member

Choose a reason for hiding this comment

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

@oscargus were you going to update this? Overall I think this is a great idea...

def test_agg_filter():
def smooth1d(x, window_len):
# copied from https://scipy-cookbook.readthedocs.io/
Expand Down
23 changes: 17 additions & 6 deletions 23 lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from matplotlib.testing._markers import needs_usetex


@image_comparison(['pdf_use14corefonts.pdf'])
# Update style when regenerating the test image
@image_comparison(['pdf_use14corefonts.pdf'],
style=("classic", "_classic_test_patch"))
def test_use14corefonts():
rcParams['pdf.use14corefonts'] = True
rcParams['font.family'] = 'sans-serif'
Expand Down Expand Up @@ -306,7 +308,9 @@ def test_pdfpages_fspath():
pdf.savefig(plt.figure())


@image_comparison(['hatching_legend.pdf'])
# Update style when regenerating the test image
@image_comparison(['hatching_legend.pdf'],
style=("classic", "_classic_test_patch"))
def test_hatching_legend():
"""Test for correct hatching on patches in legend"""
fig = plt.figure(figsize=(1, 2))
Expand All @@ -317,7 +321,9 @@ def test_hatching_legend():
fig.legend([a, b, a, b], ["", "", "", ""])


@image_comparison(['grayscale_alpha.pdf'])
# Update style when regenerating the test image
@image_comparison(['grayscale_alpha.pdf'],
style=("classic", "_classic_test_patch"))
def test_grayscale_alpha():
"""Masking images with NaN did not work for grayscale images"""
x, y = np.ogrid[-2:2:.1, -2:2:.1]
Expand Down Expand Up @@ -354,7 +360,8 @@ def test_empty_rasterized():
fig.savefig(io.BytesIO(), format="pdf")


@image_comparison(['kerning.pdf'])
# Update style when regenerating the test image
@image_comparison(['kerning.pdf'], style=("classic", "_classic_test_patch"))
def test_kerning():
fig = plt.figure()
s = "AVAVAVAVAVAVAVAV€AAVV"
Expand Down Expand Up @@ -387,7 +394,9 @@ def test_glyphs_subset():
assert subfont.get_num_glyphs() == nosubfont.get_num_glyphs()


@image_comparison(["multi_font_type3.pdf"], tol=4.6)
# Update style when regenerating the test image
@image_comparison(["multi_font_type3.pdf"], tol=4.6,
style=("classic", "_classic_test_patch"))
def test_multi_font_type3():
fp = fm.FontProperties(family=["WenQuanYi Zen Hei"])
if Path(fm.findfont(fp)).name != "wqy-zenhei.ttc":
Expand All @@ -400,7 +409,9 @@ def test_multi_font_type3():
fig.text(0.15, 0.475, "There are 几个汉字 in between!")


@image_comparison(["multi_font_type42.pdf"], tol=2.2)
# Update style when regenerating the test image
@image_comparison(["multi_font_type42.pdf"], tol=2.2,
style=("classic", "_classic_test_patch"))
def test_multi_font_type42():
fp = fm.FontProperties(family=["WenQuanYi Zen Hei"])
if Path(fm.findfont(fp)).name != "wqy-zenhei.ttc":
Expand Down
15 changes: 11 additions & 4 deletions 15 lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ def test_visibility():
parser.Parse(buf) # this will raise ExpatError if the svg is invalid


@image_comparison(['fill_black_with_alpha.svg'], remove_text=True)
@image_comparison(['fill_black_with_alpha.svg'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_fill_black_with_alpha():
fig, ax = plt.subplots()
ax.scatter(x=[0, 0.1, 1], y=[0, 0, 0], c='k', alpha=0.1, s=10000)


@image_comparison(['noscale'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['noscale'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_noscale():
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
Z = np.sin(Y ** 2)
Expand All @@ -65,7 +68,9 @@ def test_text_urls():
assert expected in buf


@image_comparison(['bold_font_output.svg'])
# Update style when regenerating the test image
@image_comparison(['bold_font_output.svg'],
style=("classic", "_classic_test_patch"))
def test_bold_font_output():
fig, ax = plt.subplots()
ax.plot(np.arange(10), np.arange(10))
Expand All @@ -74,7 +79,9 @@ def test_bold_font_output():
ax.set_title('bold-title', fontweight='bold')


@image_comparison(['bold_font_output_with_none_fonttype.svg'])
# Update style when regenerating the test image
@image_comparison(['bold_font_output_with_none_fonttype.svg'],
style=("classic", "_classic_test_patch"))
def test_bold_font_output_with_none_fonttype():
plt.rcParams['svg.fonttype'] = 'none'
fig, ax = plt.subplots()
Expand Down
23 changes: 17 additions & 6 deletions 23 lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def _colorbar_extension_length(spacing):
return fig


# Update style when regenerating the test image
@image_comparison(['colorbar_extensions_shape_uniform.png',
'colorbar_extensions_shape_proportional.png'])
'colorbar_extensions_shape_proportional.png'],
style=("classic", "_classic_test_patch"))
def test_colorbar_extension_shape():
"""Test rectangular colorbar extensions."""
# Remove this line when this test image is regenerated.
Expand All @@ -114,9 +116,10 @@ def test_colorbar_extension_shape():
_colorbar_extension_shape('proportional')


# Update style when regenerating the test image
@image_comparison(['colorbar_extensions_uniform.png',
'colorbar_extensions_proportional.png'],
tol=1.0)
tol=1.0, style=("classic", "_classic_test_patch"))
def test_colorbar_extension_length():
"""Test variable length colorbar extensions."""
# Remove this line when this test image is regenerated.
Expand Down Expand Up @@ -152,13 +155,15 @@ def test_colorbar_extension_inverted_axis(orientation, extend, expected):


@pytest.mark.parametrize('use_gridspec', [True, False])
# Update style when regenerating the test image
@image_comparison(['cbar_with_orientation',
'cbar_locationing',
'double_cbar',
'cbar_sharing',
],
extensions=['png'], remove_text=True,
savefig_kwarg={'dpi': 40})
savefig_kwarg={'dpi': 40},
style=("classic", "_classic_test_patch"))
def test_colorbar_positioning(use_gridspec):
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False
Expand Down Expand Up @@ -233,7 +238,9 @@ def test_colorbar_single_ax_panchor_east(constrained):
assert ax.get_anchor() == 'E'


@image_comparison(['contour_colorbar.png'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['contour_colorbar.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_contour_colorbar():
fig, ax = plt.subplots(figsize=(4, 2))
data = np.arange(1200).reshape(30, 40) - 500
Expand All @@ -244,8 +251,10 @@ def test_contour_colorbar():
fig.colorbar(CS, orientation='vertical')


# Update style when regenerating the test image
@image_comparison(['cbar_with_subplots_adjust.png'], remove_text=True,
savefig_kwarg={'dpi': 40})
savefig_kwarg={'dpi': 40},
style=("classic", "_classic_test_patch"))
def test_gridspec_make_colorbar():
plt.figure()
data = np.arange(1200).reshape(30, 40)
Expand All @@ -262,8 +271,10 @@ def test_gridspec_make_colorbar():
plt.subplots_adjust(top=0.95, right=0.95, bottom=0.2, hspace=0.25)


# Update style when regenerating the test image
@image_comparison(['colorbar_single_scatter.png'], remove_text=True,
savefig_kwarg={'dpi': 40})
savefig_kwarg={'dpi': 40},
style=("classic", "_classic_test_patch"))
def test_colorbar_single_scatter():
# Issue #2642: if a path collection has only one entry,
# the norm scaling within the colorbar must ensure a
Expand Down
7 changes: 5 additions & 2 deletions 7 lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def test_contour_manual_labels():
plt.clabel(cs, manual=pts, fontsize='small', colors=('r', 'g'))


@image_comparison(['contour_manual_colors_and_levels.png'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['contour_manual_colors_and_levels.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_given_colors_levels_and_extends():
# Remove this line when this test image is regenerated.
plt.rcParams['pcolormesh.snap'] = False
Expand Down Expand Up @@ -211,9 +213,10 @@ def test_labels():
CS.add_label_near(x, y, inline=True, transform=False)


# Update style when regenerating the test image
@image_comparison(['contour_corner_mask_False.png',
'contour_corner_mask_True.png'],
remove_text=True)
remove_text=True, style=("classic", "_classic_test_patch"))
def test_corner_mask():
n = 60
mask_level = 0.95
Expand Down
14 changes: 10 additions & 4 deletions 14 lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import matplotlib.dates as mdates


# Update style when regenerating the test image
@image_comparison(['figure_align_labels'], extensions=['png', 'svg'],
tol=0 if platform.machine() == 'x86_64' else 0.01)
tol=0 if platform.machine() == 'x86_64' else 0.01,
style=("classic", "_classic_test_patch"))
def test_align_labels():
fig = plt.figure(layout='tight')
gs = gridspec.GridSpec(3, 3)
Expand Down Expand Up @@ -160,7 +162,8 @@ def test_clf_keyword():
assert [t.get_text() for t in fig2.texts] == []


@image_comparison(['figure_today'])
# Update style when regenerating the test image
@image_comparison(['figure_today'], style=("classic", "_classic_test_patch"))
def test_figure():
# named figure support
fig = plt.figure('today')
Expand All @@ -175,7 +178,8 @@ def test_figure():
plt.close('tomorrow')


@image_comparison(['figure_legend'])
# Update style when regenerating the test image
@image_comparison(['figure_legend'], style=("classic", "_classic_test_patch"))
def test_figure_legend():
fig, axs = plt.subplots(2)
axs[0].plot([0, 1], [1, 0], label='x', color='g')
Expand Down Expand Up @@ -272,7 +276,9 @@ def test_add_subplot_invalid():
fig.add_subplot(ax)


@image_comparison(['figure_suptitle'])
# Update style when regenerating the test image
@image_comparison(['figure_suptitle'],
style=("classic", "_classic_test_patch"))
def test_suptitle():
fig, _ = plt.subplots()
fig.suptitle('hello', color='r')
Expand Down
12 changes: 9 additions & 3 deletions 12 lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def test_image_interps():
ax3.set_ylabel('bicubic')


@image_comparison(['interp_alpha.png'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['interp_alpha.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_alpha_interp():
"""Test the interpolation of the alpha channel on RGBA images"""
fig, (axl, axr) = plt.subplots(1, 2)
Expand All @@ -56,8 +58,10 @@ def test_alpha_interp():
axr.imshow(img, interpolation="bilinear")


# Update style when regenerating the test image
@image_comparison(['interp_nearest_vs_none'],
extensions=['pdf', 'svg'], remove_text=True)
extensions=['pdf', 'svg'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_interp_nearest_vs_none():
"""Test the effect of "nearest" and "none" interpolation"""
# Setting dpi to something really small makes the difference very
Expand All @@ -74,8 +78,10 @@ def test_interp_nearest_vs_none():
ax2.set_title('interpolation nearest')


# Update style when regenerating the test image
@pytest.mark.parametrize('suppressComposite', [False, True])
@image_comparison(['figimage'], extensions=['png', 'pdf'])
@image_comparison(['figimage'], extensions=['png', 'pdf'],
style=("classic", "_classic_test_patch"))
def test_figimage(suppressComposite):
fig = plt.figure(figsize=(2, 2), dpi=100)
fig.suppressComposite = suppressComposite
Expand Down
12 changes: 9 additions & 3 deletions 12 lib/matplotlib/tests/test_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def test_set_line_coll_dash():
ax.contour(np.random.randn(20, 30), linestyles=[(0, (3, 3))])


@image_comparison(['line_dashes'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['line_dashes'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_line_dashes():
fig, ax = plt.subplots()

Expand Down Expand Up @@ -122,7 +124,9 @@ def test_valid_linestyles():
line.set_linestyle('aardvark')


@image_comparison(['drawstyle_variants.png'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['drawstyle_variants.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_drawstyle_variants():
fig, axs = plt.subplots(6)
dss = ["default", "steps-mid", "steps-pre", "steps-post", "steps", None]
Expand Down Expand Up @@ -172,7 +176,9 @@ def test_set_line_coll_dash_image():
ax.contour(np.random.randn(20, 30), linestyles=[(0, (3, 3))])


@image_comparison(['marker_fill_styles.png'], remove_text=True)
# Update style when regenerating the test image
@image_comparison(['marker_fill_styles.png'], remove_text=True,
style=("classic", "_classic_test_patch"))
def test_marker_fill_styles():
colors = itertools.cycle([[0, 0, 1], 'g', '#ff0000', 'c', 'm', 'y',
np.array([0, 0, 0])])
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.