Skip to content

Commit 6d8bc9f

Browse files
committed
Use symlinks instead of copies for test result_images.
1 parent eca2854 commit 6d8bc9f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,18 @@ def copy_baseline(self, baseline, extension):
192192
os.path.join(self.result_dir,
193193
os.path.basename(orig_expected_fname)),
194194
'expected')
195-
if os.path.exists(orig_expected_fname):
196-
shutil.copyfile(orig_expected_fname, expected_fname)
197-
else:
198-
reason = ("Do not have baseline image {} because this "
199-
"file does not exist: {}".format(expected_fname,
200-
orig_expected_fname))
201-
raise ImageComparisonFailure(reason)
195+
try:
196+
# os.symlink errors if the target already exists.
197+
with contextlib.suppress(OSError):
198+
os.remove(expected_fname)
199+
try:
200+
os.symlink(orig_expected_fname, expected_fname)
201+
except OSError: # On Windows, symlink *may* be unavailable.
202+
shutil.copyfile(orig_expected_fname, expected_fname)
203+
except OSError:
204+
raise ImageComparisonFailure(
205+
f"Missing baseline image {expected_fname} because the "
206+
f"following file cannot be accessed: {orig_expected_fname}")
202207
return expected_fname
203208

204209
def compare(self, idx, baseline, extension):

0 commit comments

Comments
 (0)