🌐 AI搜索 & 代理 主页
Skip to content

Commit 15d0e90

Browse files
Added feature to copy to and extract from mpl_cache the baseline images
1 parent f3d31ec commit 15d0e90

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from matplotlib import ft2font
1818
from matplotlib import pyplot as plt
1919
from matplotlib import ticker
20-
20+
from matplotlib.testing.compare import get_cache_dir
2121
from .compare import comparable_formats, compare_images, make_test_filename
2222
from .exceptions import ImageComparisonFailure
2323

@@ -508,6 +508,7 @@ def _image_directories(func):
508508
doesn't exist.
509509
"""
510510
module_path = Path(sys.modules[func.__module__].__file__)
511+
cache_dir = Path(get_cache_dir()) / "baseline_images" / module_path.stem
511512
if func.__module__.startswith("matplotlib."):
512513
try:
513514
import matplotlib_baseline_images
@@ -528,7 +529,20 @@ def _image_directories(func):
528529
baseline_dir = (module_path.parent /
529530
"baseline_images" /
530531
module_path.stem)
531-
532+
extensions = ['**/*.svg', '**/*.eps', '**/*.png', '**/*.pdf']
533+
for ext in extensions:
534+
for baseline_img in Path(baseline_dir).glob(ext):
535+
cache_dir_img = (cache_dir) / \
536+
(baseline_img).relative_to(baseline_dir)
537+
if not cache_dir_img.exists():
538+
cache_dir_img.parent.mkdir(parents=True, exist_ok=True)
539+
try:
540+
shutil.copyfile(baseline_img, cache_dir_img)
541+
except shutil.SameFileError:
542+
if not cache_dir_img.exists():
543+
raise
544+
except FileNotFoundError:
545+
raise
532546
result_dir = Path().resolve() / "result_images" / module_path.stem
533547
result_dir.mkdir(parents=True, exist_ok=True)
534-
return baseline_dir, result_dir
548+
return cache_dir, result_dir

0 commit comments

Comments
 (0)