Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shorten usage of @image_comparison. #14166

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

Merged
merged 1 commit into from
May 19, 2019
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
24 changes: 22 additions & 2 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def image_comparison(baseline_images, extensions=None, tol=0,

If *None*, defaults to all supported extensions: png, pdf, and svg.

When testing a single extension, it can be directly included in the
names passed to *baseline_images*. In that case, *extensions* must not
be set.

In order to keep the size of the test suite from ballooning, we only
include the ``svg`` or ``pdf`` outputs if the test is explicitly
exercising a feature dependent on that backend (see also the
Expand Down Expand Up @@ -393,10 +397,26 @@ def image_comparison(baseline_images, extensions=None, tol=0,
Optional name for the base style to apply to the image test. The test
itself can also apply additional styles if desired. Defaults to the
'_classic_test' style.

"""

if baseline_images is not None:
# List of non-empty filename extensions.
baseline_exts = [*filter(None, {Path(baseline).suffix[1:]
for baseline in baseline_images})]
if baseline_exts:
if extensions is not None:
raise ValueError(
"When including extensions directly in 'baseline_images', "
"'extensions' cannot be set as well")
if len(baseline_exts) > 1:
raise ValueError(
"When including extensions directly in 'baseline_images', "
"all baselines must share the same suffix")
extensions = baseline_exts
baseline_images = [ # Chop suffix out from baseline_images.
Path(baseline).stem for baseline in baseline_images]
if extensions is None:
# default extensions to test
# Default extensions to test, if not set via baseline_images.
extensions = ['png', 'pdf', 'svg']

if savefig_kwarg is None:
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/tests/test_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def test_long_path():
fig.savefig(buff, format='png')


@image_comparison(baseline_images=['agg_filter'],
extensions=['png'], remove_text=True)
@image_comparison(['agg_filter.png'], remove_text=True)
def test_agg_filter():
def smooth1d(x, window_len):
s = np.r_[2*x[0] - x[window_len:1:-1],
Expand Down
20 changes: 7 additions & 13 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(baseline_images=['fancyarrow_test_image'])
@image_comparison(['fancyarrow_test_image'])
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 All @@ -28,7 +28,7 @@ def test_fancyarrow():
ax.tick_params(labelleft=False, labelbottom=False)


@image_comparison(baseline_images=['boxarrow_test_image'], extensions=['png'])
@image_comparison(['boxarrow_test_image.png'])
def test_boxarrow():

styles = mpatches.BoxStyle.get_styles()
Expand Down Expand Up @@ -67,8 +67,7 @@ def __prepare_fancyarrow_dpi_cor_test():
return fig2


@image_comparison(baseline_images=['fancyarrow_dpi_cor_100dpi'],
remove_text=True, extensions=['png'],
@image_comparison(['fancyarrow_dpi_cor_100dpi.png'], remove_text=True,
tol={'aarch64': 0.02}.get(platform.machine(), 0.0),
savefig_kwarg=dict(dpi=100))
def test_fancyarrow_dpi_cor_100dpi():
Expand All @@ -83,8 +82,7 @@ def test_fancyarrow_dpi_cor_100dpi():
__prepare_fancyarrow_dpi_cor_test()


@image_comparison(baseline_images=['fancyarrow_dpi_cor_200dpi'],
remove_text=True, extensions=['png'],
@image_comparison(['fancyarrow_dpi_cor_200dpi.png'], remove_text=True,
tol={'aarch64': 0.02}.get(platform.machine(), 0.0),
savefig_kwarg=dict(dpi=200))
def test_fancyarrow_dpi_cor_200dpi():
Expand All @@ -96,9 +94,7 @@ def test_fancyarrow_dpi_cor_200dpi():
__prepare_fancyarrow_dpi_cor_test()


@image_comparison(baseline_images=['fancyarrow_dash'],
remove_text=True, extensions=['png'],
style='default')
@image_comparison(['fancyarrow_dash.png'], remove_text=True, style='default')
def test_fancyarrow_dash():
from matplotlib.patches import FancyArrowPatch
fig, ax = plt.subplots()
Expand All @@ -122,8 +118,7 @@ def test_fancyarrow_dash():
ax.add_patch(e2)


@image_comparison(baseline_images=['arrow_styles'], extensions=['png'],
style='mpl20', remove_text=True)
@image_comparison(['arrow_styles.png'], style='mpl20', remove_text=True)
def test_arrow_styles():
styles = mpatches.ArrowStyle.get_styles()

Expand All @@ -139,8 +134,7 @@ def test_arrow_styles():
ax.add_patch(patch)


@image_comparison(baseline_images=['connection_styles'], extensions=['png'],
style='mpl20', remove_text=True)
@image_comparison(['connection_styles.png'], style='mpl20', remove_text=True)
def test_connection_styles():
styles = mpatches.ConnectionStyle.get_styles()

Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/tests/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_collection_transform_of_none():
assert isinstance(c._transOffset, mtransforms.IdentityTransform)


@image_comparison(baseline_images=["clip_path_clipping"], remove_text=True)
@image_comparison(["clip_path_clipping"], remove_text=True)
def test_clipping():
exterior = mpath.Path.unit_rectangle().deepcopy()
exterior.vertices *= 4
Expand Down Expand Up @@ -142,8 +142,7 @@ def test_cull_markers():
assert len(svg.getvalue()) < 20000


@image_comparison(baseline_images=['hatching'], remove_text=True,
style='default')
@image_comparison(['hatching'], remove_text=True, style='default')
def test_hatching():
fig, ax = plt.subplots(1, 1)

Expand Down Expand Up @@ -200,8 +199,7 @@ def test_remove():
assert ax.stale


@image_comparison(baseline_images=["default_edges"], remove_text=True,
extensions=['png'], style='default')
@image_comparison(["default_edges.png"], remove_text=True, style='default')
def test_default_edges():
fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2)

Expand Down
Loading