FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

TST: use pytest name in naming files for check_figures_equal by tacaswell · Pull Request #16693 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 13 additions & 8 deletions lib/matplotlib/testing/decorators.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 All @@ -17,7 +18,7 @@
from matplotlib import ft2font
from matplotlib import pyplot as plt
from matplotlib import ticker
from . import is_called_from_pytest

from .compare import comparable_formats, compare_images, make_test_filename
from .exceptions import ImageComparisonFailure

Expand Down Expand Up @@ -381,22 +382,23 @@ def test_plot(fig_test, fig_ref):
fig_test.subplots().plot([1, 3, 5])
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
"""
POSITIONAL_OR_KEYWORD = inspect.Parameter.POSITIONAL_OR_KEYWORD
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
def decorator(func):
import pytest

_, result_dir = _image_directories(func)

@pytest.mark.parametrize("ext", extensions)
def wrapper(*args, ext, **kwargs):
def wrapper(*args, ext, request, **kwargs):
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 / (func.__name__ + "." + ext)
ref_image_path = result_dir / (
func.__name__ + "-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 All @@ -411,7 +413,10 @@ def wrapper(*args, ext, **kwargs):
parameters=([param
for param in sig.parameters.values()
if param.name not in {"fig_test", "fig_ref"}]
+ [inspect.Parameter("ext", POSITIONAL_OR_KEYWORD)])
+ [
inspect.Parameter("ext", KEYWORD_ONLY),
inspect.Parameter("request", KEYWORD_ONLY),
])
)
wrapper.__signature__ = new_sig

Expand Down

Back | FazBrowse Home | New Git URL