Skip to content

Commit 5c3228a

Browse files
authored
Merge pull request #615 from PyAutoLabs/feature/coolest-standard-support
fix: COOLEST interop rejects relative file paths
2 parents 3cb97b6 + a15744d commit 5c3228a

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

autolens/interop/coolest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def _coolest_modules():
7171

7272

7373
def _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"

test_autolens/interop/test_coolest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
149165
def test__from_coolest__missing_point_estimate_raises(tmp_path):
150166
pytest.importorskip("coolest")
151167
from coolest.template.lazy import (

0 commit comments

Comments
 (0)