Skip to content

Commit 3dea5bc

Browse files
committed
test: write test output to tmp_path, untrack generated FITS artifacts
test_autoarray wrote test *output* into tracked paths, so any change to the autonerves FITS writer rewrote a committed binary and dirtied the tree for every contributor. #483 demonstrated it: the PyAutoNerves#155 header-comment fix ([""] -> "") silently modified structures/arrays/files/array/output_test/array.fits the moment the autonerves floor moved -- identical cards, values, data and byte size, but a modified tracked file that had to be committed into an unrelated PR. Applies the durable fix uniformly rather than patching file-by-file again: the nine tests that wrote into an output_test/ directory now take pytest's tmp_path and drop their rmtree/makedirs preamble. After a full run no output_test/ directory is created anywhere in the source tree. Untracks the 13 exposed artifacts. Only one of them was a live output -- the array.fits that #483 flipped. The other twelve were orphans: no test referenced their paths, and a repo-wide grep for their basenames returned nothing. They were residue from tests deleted long ago, as were the two file-by-file .gitignore lines, now replaced by a test_autoarray/**/output_test/ pattern that serves as a backstop against a future writer regressing this. Two incidental fixes fall out. test_uniform_1d and test_uniform_2d both rmtree'd the same shared output directory, an ordering hazard tmp_path removes. And the three imaging tests that took the test_data_path fixture wrote their generated FITS into the source tree via that fixture; they now use tmp_path and the fixture is gone. Verified from a clean checkout: 1177 passed, 55 skipped, run twice in a row with git status clean after each -- the second run is what would catch a test that had silently depended on a committed artifact. Closes #494 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QoAeGsJyiaLG4oqXb9n3dM
1 parent 2c06e4a commit 3dea5bc

20 files changed

Lines changed: 48 additions & 106 deletions

File tree

‎.gitignore‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ test_autoarray/mask/files/mask/mask_out.fits
66
test_autoarray/plot/wrap/base/files/
77
test_autoarray/structures/grids/files/grid_2d.fits
88

9-
test_autoarray/dataset/files/array/output_test/uv_wavelengths.fits
10-
test_autoarray/dataset/files/array/output_test/visibilities.fits
9+
# Test output: tests write results into output_test/ dirs and read them back.
10+
# Never track them -- a change to the autonerves FITS writer would otherwise
11+
# rewrite a committed binary and dirty every contributor's tree (PyAutoArray#483).
12+
test_autoarray/**/output_test/
1113
test_autoarray/dataset/plot/files/
1214
test_autoarray/fit/plot/files/
1315
test_autoarray/structures/arrays/one_d/files/array/
-5.63 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-5.63 KB
Binary file not shown.
-5.63 KB
Binary file not shown.
Binary file not shown.
-5.63 KB
Binary file not shown.

‎test_autoarray/dataset/imaging/test_dataset.py‎

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import copy
2-
import os
32

43
import numpy as np
54
import pytest
6-
import shutil
75

86
import autoarray as aa
97

@@ -13,18 +11,6 @@
1311
test_data_path = Path(Path(__file__).resolve().parent) / "files"
1412

1513

16-
@pytest.fixture(name="test_data_path")
17-
def make_test_data_path():
18-
test_data_path = Path(__file__).resolve().parent / "files" / "array" / "output_test"
19-
20-
if test_data_path.exists():
21-
shutil.rmtree(test_data_path)
22-
23-
os.makedirs(test_data_path)
24-
25-
return test_data_path
26-
27-
2814
def test__grid__uses_mask_and_settings__lp_grid_matches_grid_2d_7x7(
2915
image_7x7,
3016
noise_map_7x7,
@@ -162,27 +148,25 @@ def test__from_fits__all_data_in_one_fits_file_multiple_hdus__loads_data_psf_noi
162148
assert dataset.noise_map.mask.pixel_scales == (0.1, 0.1)
163149

164150

165-
def test__from_fits__small_datasets_env_caps_data_and_noise_map(
166-
test_data_path, monkeypatch
167-
):
151+
def test__from_fits__small_datasets_env_caps_data_and_noise_map(tmp_path, monkeypatch):
168152
"""When PYAUTO_SMALL_DATASETS=1, Imaging.from_fits center-crops data and
169153
noise_map to (15, 15) at pixel_scales=0.6 so they stay shape-consistent
170154
with masks built via Mask2D.circular under the same env var. PSF is left
171155
alone."""
172156
from astropy.io import fits
173157

174158
fits.writeto(
175-
Path(test_data_path) / "data_30x30.fits",
159+
tmp_path / "data_30x30.fits",
176160
data=np.ones((30, 30), dtype=np.float64),
177161
overwrite=True,
178162
)
179163
fits.writeto(
180-
Path(test_data_path) / "noise_map_30x30.fits",
164+
tmp_path / "noise_map_30x30.fits",
181165
data=2.0 * np.ones((30, 30), dtype=np.float64),
182166
overwrite=True,
183167
)
184168
fits.writeto(
185-
Path(test_data_path) / "psf_5x5.fits",
169+
tmp_path / "psf_5x5.fits",
186170
data=(1.0 / 25.0) * np.ones((5, 5), dtype=np.float64),
187171
overwrite=True,
188172
)
@@ -191,9 +175,9 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map(
191175

192176
dataset = aa.Imaging.from_fits(
193177
pixel_scales=0.08,
194-
data_path=Path(test_data_path) / "data_30x30.fits",
195-
psf_path=Path(test_data_path) / "psf_5x5.fits",
196-
noise_map_path=Path(test_data_path) / "noise_map_30x30.fits",
178+
data_path=tmp_path / "data_30x30.fits",
179+
psf_path=tmp_path / "psf_5x5.fits",
180+
noise_map_path=tmp_path / "noise_map_30x30.fits",
197181
)
198182

199183
assert dataset.data.shape_native == (16, 16)
@@ -202,20 +186,18 @@ def test__from_fits__small_datasets_env_caps_data_and_noise_map(
202186
assert dataset.psf.kernel.shape_native == (5, 5)
203187

204188

205-
def test__from_fits__small_datasets_env_unset__shape_unchanged(
206-
test_data_path, monkeypatch
207-
):
189+
def test__from_fits__small_datasets_env_unset__shape_unchanged(tmp_path, monkeypatch):
208190
"""Sanity: with the env var unset, from_fits returns the on-disk shape
209191
unchanged, even for files larger than the cap."""
210192
from astropy.io import fits
211193

212194
fits.writeto(
213-
Path(test_data_path) / "data_30x30.fits",
195+
tmp_path / "data_30x30.fits",
214196
data=np.ones((30, 30), dtype=np.float64),
215197
overwrite=True,
216198
)
217199
fits.writeto(
218-
Path(test_data_path) / "noise_map_30x30.fits",
200+
tmp_path / "noise_map_30x30.fits",
219201
data=2.0 * np.ones((30, 30), dtype=np.float64),
220202
overwrite=True,
221203
)
@@ -224,34 +206,32 @@ def test__from_fits__small_datasets_env_unset__shape_unchanged(
224206

225207
dataset = aa.Imaging.from_fits(
226208
pixel_scales=0.08,
227-
data_path=Path(test_data_path) / "data_30x30.fits",
228-
noise_map_path=Path(test_data_path) / "noise_map_30x30.fits",
209+
data_path=tmp_path / "data_30x30.fits",
210+
noise_map_path=tmp_path / "noise_map_30x30.fits",
229211
)
230212

231213
assert dataset.data.shape_native == (30, 30)
232214
assert dataset.noise_map.shape_native == (30, 30)
233215
assert dataset.pixel_scales == (0.08, 0.08)
234216

235217

236-
def test__output_to_fits__round_trips_data_psf_noise_map_correctly(
237-
imaging_7x7, test_data_path
238-
):
218+
def test__output_to_fits__round_trips_data_psf_noise_map_correctly(imaging_7x7, tmp_path):
239219

240220
from autoarray.dataset.plot.imaging_plots import fits_imaging
241221

242222
fits_imaging(
243223
dataset=imaging_7x7,
244-
data_path=Path(test_data_path) / "data.fits",
245-
psf_path=Path(test_data_path) / "psf.fits",
246-
noise_map_path=Path(test_data_path) / "noise_map.fits",
224+
data_path=tmp_path / "data.fits",
225+
psf_path=tmp_path / "psf.fits",
226+
noise_map_path=tmp_path / "noise_map.fits",
247227
overwrite=True,
248228
)
249229

250230
dataset = aa.Imaging.from_fits(
251231
pixel_scales=0.1,
252-
data_path=Path(test_data_path) / "data.fits",
253-
psf_path=Path(test_data_path) / "psf.fits",
254-
noise_map_path=Path(test_data_path) / "noise_map.fits",
232+
data_path=tmp_path / "data.fits",
233+
psf_path=tmp_path / "psf.fits",
234+
noise_map_path=tmp_path / "noise_map.fits",
255235
)
256236

257237
assert (dataset.data.native == np.ones((7, 7))).all()

0 commit comments

Comments
 (0)