Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitb0d63b5

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 parentf10bcee commitb0d63b5

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 twokeywordarguments, *fig_test*
363+
and*fig_ref*, anddraw the test and reference images on them.
364+
After the functionreturns, 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+
ifnotall(kinold_sig.parametersforkin {"fig_test","fig_ref"}):
396+
raiseValueError("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
defwrapper(*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
deftest_parametrize_with_check_figure_equal(a,fig_ref,b,fig_test):
1717
asserta==b
18+
19+
20+
deftest_wrap_failure():
21+
withpytest.raises(ValueError,match="^The decorated function"):
22+
@check_figures_equal()
23+
defshould_fail(test,ref):
24+
pass

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp