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 cdad366

Browse filesBrowse files
committed
Merge pull request matplotlib#16693 from tacaswell/tst_better_compare_names
TST: use pytest name in naming files for check_figures_equal
1 parent 9211537 commit cdad366
Copy full SHA for cdad366

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+13
-8
lines changed

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+13-8Lines 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

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

388390
_, result_dir = _image_directories(func)
389391

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

0 commit comments

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