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

Skip to content

Commit a66d8d8

Browse files
committed
MNT: filter filename to not fail non-allowed names
This is probably to stringent but this is better than blindly using the test name from pytest.
1 parent 3b57fba commit a66d8d8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 6 additions & 3 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
@@ -381,6 +382,7 @@ 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
"""
385+
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
384386
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
385387
def decorator(func):
386388
import pytest
@@ -389,13 +391,14 @@ def decorator(func):
389391

390392
@pytest.mark.parametrize("ext", extensions)
391393
def wrapper(*args, ext, request, **kwargs):
392-
fn = request.node.name
394+
file_name = "".join(c for c in request.node.name
395+
if c in ALLOWED_CHARS)
393396
try:
394397
fig_test = plt.figure("test")
395398
fig_ref = plt.figure("reference")
396399
func(*args, fig_test=fig_test, fig_ref=fig_ref, **kwargs)
397-
test_image_path = result_dir / (fn + "." + ext)
398-
ref_image_path = result_dir / (fn + "-expected." + ext)
400+
test_image_path = result_dir / (file_name + "." + ext)
401+
ref_image_path = result_dir / (file_name + "-expected." + ext)
399402
fig_test.savefig(test_image_path)
400403
fig_ref.savefig(ref_image_path)
401404
_raise_on_image_difference(

0 commit comments

Comments
 (0)