Skip to content

Commit

Permalink
Ensure that pytest can be used with check_figures_equal
Browse files Browse the repository at this point in the history
Same logic that was implemented in
matplotlib/matplotlib#16800
  • Loading branch information
weiji14 committed Sep 3, 2020
1 parent d2ad3f5 commit d3cab24
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
etc.
"""
import functools
import inspect
import os
import textwrap

Expand Down Expand Up @@ -446,14 +447,15 @@ def check_figures_equal(*, result_dir="result_images", tol=0.0):
def decorator(func):

os.makedirs(result_dir, exist_ok=True)
old_sig = inspect.signature(func)

def wrapper():
def wrapper(*args, **kwargs):
try:
from ..figure import Figure # pylint: disable=import-outside-toplevel

fig_ref = Figure()
fig_test = Figure()
func(fig_ref, fig_test)
func(*args, fig_ref=fig_ref, fig_test=fig_test, **kwargs)
ref_image_path = os.path.join(
result_dir, func.__name__ + "-expected.png"
)
Expand Down Expand Up @@ -483,6 +485,14 @@ def wrapper():
del fig_ref
del fig_test

parameters = [
param
for param in old_sig.parameters.values()
if param.name not in {"fig_test", "fig_ref"}
]
new_sig = old_sig.replace(parameters=parameters)
wrapper.__signature__ = new_sig

return wrapper

return decorator

0 comments on commit d3cab24

Please sign in to comment.