8000 Use symlinks instead of copies for test result_images. · matplotlib/matplotlib@2051b6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 2051b6f

Browse files
committed
Use symlinks instead of copies for test result_images.
1 parent 150faa1 commit 2051b6f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,19 @@ 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+
try: # os.symlink errors if the target already exists.
197+
os.remove(expected_fname)
198+
except OSError:
199+
pass
200+
try:
201+
os.symlink(orig_expected_fname, expected_fname)
202+
except OSError: # On Windows, symlink *may* be unavailable.
203+
shutil.copyfile(orig_expected_fname, expected_fname)
204+
except OSError:
205+
raise ImageComparisonFailure(
206+
f"Missing baseline image {expected_fname} because the "
207+
f"following file cannot be accessed: {orig_expected_fname}")
202208
return expected_fname
203209

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

0 commit comments

Comments
 (0)
0