Skip to content

Commit 20f7ec2

Browse files
Jammy2211claude
authored andcommitted
test: lock down WeakDataset / ShearYX2DIrregular json round-trip
Regression test for the failure mode that surfaced in PR #525 — al.from_json on a serialised WeakDataset previously crashed with: TypeError: VectorYX2DIrregular.__init__() missing 1 required positional argument: 'values' The library-side fix lives in PyAutoArray (a `values` property on VectorYX2DIrregular). This test asserts the full simulator → write → load path, including subclass preservation — loaded.shear_yx returns as ShearYX2DIrregular, not the base class — plus matching shear values, grid positions, and noise map. Refs issue #554. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 01c4457 commit 20f7ec2

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

test_autolens/weak/test_dataset.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,25 @@ def test__weak_dataset__extent_from_pads_position_bounding_box():
7777
assert y_max == pytest.approx(1.1)
7878
assert x_min == pytest.approx(-0.5)
7979
assert x_max == pytest.approx(2.1)
80+
81+
82+
def test__weak_dataset__json_round_trip(tmp_path):
83+
shear_yx = _make_shear_yx(
84+
positions=[(0.5, 0.0), (-0.5, 0.0), (0.0, 0.5), (0.0, -0.5)],
85+
values=[(0.01, 0.02), (-0.03, 0.04), (0.05, -0.06), (0.07, 0.08)],
86+
)
87+
88+
dataset = al.WeakDataset(
89+
shear_yx=shear_yx, noise_map=[0.2, 0.3, 0.25, 0.35], name="round_trip"
90+
)
91+
92+
file_path = tmp_path / "dataset.json"
93+
al.output_to_json(obj=dataset, file_path=file_path)
94+
loaded = al.from_json(file_path=file_path)
95+
96+
assert isinstance(loaded, al.WeakDataset)
97+
assert isinstance(loaded.shear_yx, ShearYX2DIrregular)
98+
assert loaded.name == "round_trip"
99+
assert np.allclose(loaded.shear_yx.array, dataset.shear_yx.array)
100+
assert np.allclose(loaded.shear_yx.grid.array, dataset.shear_yx.grid.array)
101+
assert np.allclose(loaded.noise_map.array, dataset.noise_map.array)

0 commit comments

Comments
 (0)