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

Commit 408f55d

Browse filesBrowse files
committed
Make check_figures_equal work on methods too.
1 parent 0fec7f1 commit 408f55d
Copy full SHA for 408f55d

File tree

Expand file treeCollapse file tree

1 file changed

+31
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-13
lines changed

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+31-13Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,19 +452,37 @@ def decorator(func):
452452

453453
_, result_dir = map(Path, _image_directories(func))
454454

455-
@pytest.mark.parametrize("ext", extensions)
456-
def wrapper(ext):
457-
fig_test = plt.figure("test")
458-
fig_ref = plt.figure("reference")
459-
func(fig_test, fig_ref)
460-
test_image_path = str(
461-
result_dir / (func.__name__ + "." + ext))
462-
ref_image_path = str(
463-
result_dir / (func.__name__ + "-expected." + ext))
464-
fig_test.savefig(test_image_path)
465-
fig_ref.savefig(ref_image_path)
466-
_raise_on_image_difference(
467-
ref_image_path, test_image_path, tol=tol)
455+
if len(inspect.signature(func).parameters) == 2:
456+
# Free-standing function.
457+
@pytest.mark.parametrize("ext", extensions)
458+
def wrapper(ext):
459+
fig_test = plt.figure("test")
460+
fig_ref = plt.figure("reference")
461+
func(fig_test, fig_ref)
462+
test_image_path = str(
463+
result_dir / (func.__name__ + "." + ext))
464+
ref_image_path = str(
465+
result_dir / (func.__name__ + "-expected." + ext))
466+
fig_test.savefig(test_image_path)
467+
fig_ref.savefig(ref_image_path)
468+
_raise_on_image_difference(
469+
ref_image_path, test_image_path, tol=tol)
470+
471+
elif len(inspect.signature(func).parameters) == 3:
472+
# Method.
473+
@pytest.mark.parametrize("ext", extensions)
474+
def wrapper(self, ext):
475+
fig_test = plt.figure("test")
476+
fig_ref = plt.figure("reference")
477+
func(self, fig_test, fig_ref)
478+
test_image_path = str(
479+
result_dir / (func.__name__ + "." + ext))
480+
ref_image_path = str(
481+
result_dir / (func.__name__ + "-expected." + ext))
482+
fig_test.savefig(test_image_path)
483+
fig_ref.savefig(ref_image_path)
484+
_raise_on_image_difference(
485+
ref_image_path, test_image_path, tol=tol)
468486

469487
return wrapper
470488

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.