4
4
import inspect
5
5
import json
6
6
import os
7
- from pathlib import Path
7
+ from pathlib import Path , PurePosixPath
8
8
from platform import uname
9
9
import shutil
10
10
import string
@@ -152,7 +152,7 @@ def copy_baseline(self, baseline, extension):
152
152
153
153
rel_path = orig_expected_path .relative_to (self .root_dir )
154
154
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.' )
156
156
if self .mode != self ._ImageCheckMode .TEST :
157
157
return orig_expected_path
158
158
expected_fname = Path (make_test_filename (
@@ -200,7 +200,8 @@ def compare(self, fig, baseline, extension, *, _lock=False):
200
200
# TODO make sure the file exists (and cache?)
201
201
if self .md_path .exists ():
202
202
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
+
204
205
else :
205
206
md = {}
206
207
self .md_path .parent .mkdir (parents = True , exist_ok = True )
@@ -210,14 +211,20 @@ def compare(self, fig, baseline, extension, *, _lock=False):
210
211
expected_path .parent .mkdir (parents = True , exist_ok = True )
211
212
shutil .copyfile (actual_path , expected_path )
212
213
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
+ }
216
218
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
+ )
218
225
else :
219
226
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' ]:
221
228
raise RuntimeError ("Baseline images do not match checkout." )
222
229
_raise_on_image_difference (expected_path , actual_path , self .tol )
223
230
0 commit comments