1717from matplotlib import ft2font
1818from matplotlib import pyplot as plt
1919from matplotlib import ticker
20-
20+ from matplotlib . testing . compare import get_cache_dir
2121from .compare import comparable_formats , compare_images , make_test_filename
2222from .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