Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
tacaswell committed Mar 15, 2020
commit a66d8d8ea14bcdca82670f4d0945fb03042d0a30
9 changes: 6 additions & 3 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import unittest
import warnings
import string

import matplotlib as mpl
import matplotlib.style
Expand Down Expand Up @@ -381,6 +382,7 @@ def test_plot(fig_test, fig_ref):
fig_test.subplots().plot([1, 3, 5])
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
"""
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
def decorator(func):
import pytest
Expand All @@ -389,13 +391,14 @@ def decorator(func):

@pytest.mark.parametrize("ext", extensions)
def wrapper(*args, ext, request, **kwargs):
fn = request.node.name
file_name = "".join(c for c in request.node.name
if c in ALLOWED_CHARS)
try:
fig_test = plt.figure("test")
fig_ref = plt.figure("reference")
func(*args, fig_test=fig_test, fig_ref=fig_ref, **kwargs)
test_image_path = result_dir / (fn + "." + ext)
ref_image_path = result_dir / (fn + "-expected." + ext)
test_image_path = result_dir / (file_name + "." + ext)
ref_image_path = result_dir / (file_name + "-expected." + ext)
fig_test.savefig(test_image_path)
fig_ref.savefig(ref_image_path)
_raise_on_image_difference(
Expand Down