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

Skip to content

Commit b4a414f

Browse files
authored
Merge pull request #16693 from tacaswell/tst_better_compare_names
TST: use pytest name in naming files for check_figures_equal
2 parents fe5f3a5 + 3788e3c commit b4a414f

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import unittest
1010
import warnings
11+
import string
1112

1213
import matplotlib as mpl
1314
import matplotlib.style
@@ -17,7 +18,7 @@
1718
from matplotlib import ft2font
1819
from matplotlib import pyplot as plt
1920
from matplotlib import ticker
20-
from . import is_called_from_pytest
21+
2122
from .compare import comparable_formats, compare_images, make_test_filename
2223
from .exceptions import ImageComparisonFailure
2324

@@ -382,22 +383,23 @@ def test_plot(fig_test, fig_ref):
382383
fig_test.subplots().plot([1, 3, 5])
383384
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
384385
"""
385-
POSITIONAL_OR_KEYWORD = inspect.Parameter.POSITIONAL_OR_KEYWORD
386+
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
387+
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
386388
def decorator(func):
387389
import pytest
388390

389391
_, result_dir = _image_directories(func)
390392

391393
@pytest.mark.parametrize("ext", extensions)
392-
def wrapper(*args, ext, **kwargs):
394+
def wrapper(*args, ext, request, **kwargs):
395+
file_name = "".join(c for c in request.node.name
396+
if c in ALLOWED_CHARS)
393397
try:
394398
fig_test = plt.figure("test")
395399
fig_ref = plt.figure("reference")
396400
func(*args, fig_test=fig_test, fig_ref=fig_ref, **kwargs)
397-
test_image_path = result_dir / (func.__name__ + "." + ext)
398-
ref_image_path = result_dir / (
399-
func.__name__ + "-expected." + ext
400-
)
401+
test_image_path = result_dir / (file_name + "." + ext)
402+
ref_image_path = result_dir / (file_name + "-expected." + ext)
401403
fig_test.savefig(test_image_path)
402404
fig_ref.savefig(ref_image_path)
403405
_raise_on_image_difference(
@@ -412,7 +414,10 @@ def wrapper(*args, ext, **kwargs):
412414
parameters=([param
413415
for param in sig.parameters.values()
414416
if param.name not in {"fig_test", "fig_ref"}]
415-
+ [inspect.Parameter("ext", POSITIONAL_OR_KEYWORD)])
417+
+ [
418+
inspect.Parameter("ext", KEYWORD_ONLY),
419+
inspect.Parameter("request", KEYWORD_ONLY),
420+
])
416421
)
417422
wrapper.__signature__ = new_sig
418423

0 commit comments

Comments
 (0)