From 20f7ec2d20c61e98201619e284d8b47926555c99 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 28 May 2026 11:18:06 +0100 Subject: [PATCH] test: lock down WeakDataset / ShearYX2DIrregular json round-trip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- test_autolens/weak/test_dataset.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test_autolens/weak/test_dataset.py b/test_autolens/weak/test_dataset.py index efaf5f2eb..0c03b79b6 100644 --- a/test_autolens/weak/test_dataset.py +++ b/test_autolens/weak/test_dataset.py @@ -77,3 +77,25 @@ def test__weak_dataset__extent_from_pads_position_bounding_box(): assert y_max == pytest.approx(1.1) assert x_min == pytest.approx(-0.5) assert x_max == pytest.approx(2.1) + + +def test__weak_dataset__json_round_trip(tmp_path): + shear_yx = _make_shear_yx( + positions=[(0.5, 0.0), (-0.5, 0.0), (0.0, 0.5), (0.0, -0.5)], + values=[(0.01, 0.02), (-0.03, 0.04), (0.05, -0.06), (0.07, 0.08)], + ) + + dataset = al.WeakDataset( + shear_yx=shear_yx, noise_map=[0.2, 0.3, 0.25, 0.35], name="round_trip" + ) + + file_path = tmp_path / "dataset.json" + al.output_to_json(obj=dataset, file_path=file_path) + loaded = al.from_json(file_path=file_path) + + assert isinstance(loaded, al.WeakDataset) + assert isinstance(loaded.shear_yx, ShearYX2DIrregular) + assert loaded.name == "round_trip" + assert np.allclose(loaded.shear_yx.array, dataset.shear_yx.array) + assert np.allclose(loaded.shear_yx.grid.array, dataset.shear_yx.grid.array) + assert np.allclose(loaded.noise_map.array, dataset.noise_map.array)