Skip to content

Commit b5e30d5

Browse files
committed
MNT: try to use Paths everywhere to try and fix windows
1 parent 0f07609 commit b5e30d5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import inspect
55
import json
66
import os
7-
from pathlib import Path
7+
from pathlib import Path, PurePosixPath
88
from platform import uname
99
import shutil
1010
import string
@@ -152,7 +152,7 @@ def copy_baseline(self, baseline, extension):
152152

153153
rel_path = orig_expected_path.relative_to(self.root_dir)
154154
if rel_path not in self.image_revs:
155-
raise ValueError(f'{rel_path} is not known.')
155+
raise ValueError(f'{rel_path!r} is not known.')
156156
if self.mode != self._ImageCheckMode.TEST:
157157
return orig_expected_path
158158
expected_fname = Path(make_test_filename(
@@ -200,7 +200,8 @@ def compare(self, fig, baseline, extension, *, _lock=False):
200200
# TODO make sure the file exists (and cache?)
201201
if self.md_path.exists():
202202
with open(self.md_path) as fin:
203-
md = json.load(fin)
203+
md = {Path(k): v for k, v in json.load(fin).items()}
204+
204205
else:
205206
md = {}
206207
self.md_path.parent.mkdir(parents=True, exist_ok=True)
@@ -210,14 +211,20 @@ def compare(self, fig, baseline, extension, *, _lock=False):
210211
expected_path.parent.mkdir(parents=True, exist_ok=True)
211212
shutil.copyfile(actual_path, expected_path)
212213

213-
md[str(rel_path)] = {'mpl_version': matplotlib.__version__,
214-
**{k: self.image_revs[rel_path][k]
215-
for k in ('sha', 'rev')}}
214+
md[rel_path] = {
215+
'mpl_version': matplotlib.__version__,
216+
**{k: self.image_revs[rel_path][k]for k in ('sha', 'rev')}
217+
}
216218
with open(self.md_path, 'w') as fout:
217-
json.dump(md, fout, sort_keys=True, indent=' ')
219+
json.dump(
220+
{str(PurePosixPath(*k.parts)): v for k, v in md.items()},
221+
fout,
222+
sort_keys=True,
223+
indent=' '
224+
)
218225
else:
219226
rel_path = actual_path.relative_to(self.result_dir.parent)
220-
if md[str(rel_path)]['sha'] != self.image_revs[rel_path]['sha']:
227+
if md[rel_path]['sha'] != self.image_revs[rel_path]['sha']:
221228
raise RuntimeError("Baseline images do not match checkout.")
222229
_raise_on_image_difference(expected_path, actual_path, self.tol)
223230

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy