File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ def _coolest_modules():
7171
7272
7373def _path_no_ext (file_path : str ) -> str :
74+ # The coolest JSONSerializer rejects relative paths.
75+ file_path = os .path .abspath (file_path )
7476 if file_path .endswith (".json" ):
7577 return file_path [: - len (".json" )]
7678 return file_path
@@ -245,7 +247,7 @@ def to_coolest(
245247 )
246248
247249 path_no_ext = _path_no_ext (file_path )
248- os .makedirs (os .path .dirname (os . path . abspath ( path_no_ext ) ), exist_ok = True )
250+ os .makedirs (os .path .dirname (path_no_ext ), exist_ok = True )
249251 JSONSerializer (path_no_ext , obj = root , check_external_files = False ).dump_simple ()
250252
251253 return f"{ path_no_ext } .json"
Original file line number Diff line number Diff line change @@ -146,6 +146,22 @@ def test__round_trip__nfw_uses_sigma_crit_from_cosmology(tmp_path):
146146 assert nfw_default .kappa_s == pytest .approx (0.15 , rel = 1e-3 )
147147
148148
149+ def test__round_trip__relative_file_path (tmp_path , monkeypatch ):
150+ # The coolest JSONSerializer rejects relative paths — to_coolest /
151+ # from_coolest must absolutize them.
152+ monkeypatch .chdir (tmp_path )
153+
154+ file_path = interop_coolest .to_coolest (
155+ galaxies = lens_model_galaxies (), file_path = "template"
156+ )
157+
158+ assert file_path == str (tmp_path / "template.json" )
159+
160+ tracer_back = interop_coolest .from_coolest (file_path = "template.json" )
161+
162+ assert len (tracer_back .galaxies ) == 3
163+
164+
149165def test__from_coolest__missing_point_estimate_raises (tmp_path ):
150166 pytest .importorskip ("coolest" )
151167 from coolest .template .lazy import (
You can’t perform that action at this time.
0 commit comments