Skip to content

Commit b0d63b5

Browse files
committed
DOC/FIX: clarify the docs for check_figures_equal
Clarify that the names matter and add a check with a better exception. closes #16916
1 parent f10bcee commit b0d63b5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ def check_figures_equal(*, extensions=("png", "pdf", "svg"), tol=0):
359359
"""
360360
Decorator for test cases that generate and compare two figures.
361361
362-
The decorated function must take two arguments, *fig_test* and *fig_ref*,
363-
and draw the test and reference images on them. After the function
364-
returns, the figures are saved and compared.
362+
The decorated function must take two keyword arguments, *fig_test*
363+
and *fig_ref*, and draw the test and reference images on them.
364+
After the function returns, the figures are saved and compared.
365365
366366
This decorator should be preferred over `image_comparison` when possible in
367367
order to keep the size of the test suite from ballooning.
@@ -382,6 +382,7 @@ def check_figures_equal(*, extensions=("png", "pdf", "svg"), tol=0):
382382
def test_plot(fig_test, fig_ref):
383383
fig_test.subplots().plot([1, 3, 5])
384384
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
385+
385386
"""
386387
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
387388
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
@@ -391,6 +392,11 @@ def decorator(func):
391392
_, result_dir = _image_directories(func)
392393
old_sig = inspect.signature(func)
393394

395+
if not all(k in old_sig.parameters for k in {"fig_test", "fig_ref"}):
396+
raise ValueError("The decorated function must have at least the "
397+
"parameters 'fig_ref' and 'fig_test', but your "
398+
f"function has the signature {old_sig}")
399+
394400
@pytest.mark.parametrize("ext", extensions)
395401
def wrapper(*args, **kwargs):
396402
ext = kwargs['ext']

lib/matplotlib/tests/test_testing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ def test_warn_to_fail():
1515
@pytest.mark.parametrize("b", [1])
1616
def test_parametrize_with_check_figure_equal(a, fig_ref, b, fig_test):
1717
assert a == b
18+
19+
20+
def test_wrap_failure():
21+
with pytest.raises(ValueError, match="^The decorated function"):
22+
@check_figures_equal()
23+
def should_fail(test, ref):
24+
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy