Skip to content

Commit 9b209b9

Browse files
committed
MNT: handle creating the metadata json file if needed
1 parent 224db5d commit 9b209b9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,13 @@ def compare(self, fig, baseline, extension, *, _lock=False):
192192
plt.close(fig)
193193
expected_path = self.copy_baseline(baseline, extension)
194194
# TODO make sure the file exists (and cache?)
195-
with open(self.root_dir / 'metadata.json') as fin:
196-
md = json.load(fin)
195+
json_path = self.root_dir / 'metadata.json'
196+
if json_path.exists():
197+
with open(json_path) as fin:
198+
md = json.load(fin)
199+
else:
200+
md = {}
201+
json_path.parent.mkdir(parents=True, exist_ok=True)
197202
if self.mode == self._ImageCheckMode.GENERATE:
198203
rel_path = expected_path.relative_to(self.root_dir)
199204

0 commit comments

Comments
 (0)