From 3dea5bc34180b9c2cd9e76f41bd62cb75bdce163 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 27 Aug 2026 18:21:59 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01QoAeGsJyiaLG4oqXb9n3dM --- .gitignore | 6 +- .../files/array/output_test/noise_map.fits | Bin 5760 -> 0 bytes .../output_test/background_noise_map.fits | Bin 5760 -> 0 bytes .../output_test/background_sky_map.fits | Bin 5760 -> 0 bytes .../arrays/output_test/exposure_time_map.fits | Bin 5760 -> 0 bytes .../files/arrays/output_test/image.fits | Bin 5760 -> 0 bytes .../files/arrays/output_test/noise_map.fits | Bin 5760 -> 0 bytes .../arrays/output_test/poisson_noise_map.fits | Bin 5760 -> 0 bytes .../dataset/files/arrays/output_test/psf.fits | Bin 5760 -> 0 bytes .../dataset/imaging/test_dataset.py | 58 ++++++------------ .../dataset/interferometer/test_dataset.py | 23 +++---- test_autoarray/mask/test_mask_2d.py | 19 ++---- .../arrays/files/array/output_test/array.fits | Bin 5760 -> 0 bytes .../arrays/files/output_test/array.fits | Bin 5760 -> 0 bytes .../files/output_test/masked_array.fits | Bin 5760 -> 0 bytes .../arrays/files/output_test/values_test.dat | 1 - .../files/values/output_test/values_test.dat | 1 - .../structures/arrays/test_uniform_1d.py | 15 ++--- .../structures/arrays/test_uniform_2d.py | 16 ++--- .../structures/test_visibilities.py | 15 +---- 20 files changed, 48 insertions(+), 106 deletions(-) delete mode 100644 test_autoarray/dataset/files/array/output_test/noise_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/background_noise_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/exposure_time_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/image.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/noise_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/poisson_noise_map.fits delete mode 100644 test_autoarray/dataset/files/arrays/output_test/psf.fits delete mode 100644 test_autoarray/structures/arrays/files/array/output_test/array.fits delete mode 100644 test_autoarray/structures/arrays/files/output_test/array.fits delete mode 100644 test_autoarray/structures/arrays/files/output_test/masked_array.fits delete mode 100644 test_autoarray/structures/arrays/files/output_test/values_test.dat delete mode 100644 test_autoarray/structures/arrays/files/values/output_test/values_test.dat diff --git a/.gitignore b/.gitignore index 005f4bab3..ca50439cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,10 @@ test_autoarray/mask/files/mask/mask_out.fits test_autoarray/plot/wrap/base/files/ test_autoarray/structures/grids/files/grid_2d.fits -test_autoarray/dataset/files/array/output_test/uv_wavelengths.fits -test_autoarray/dataset/files/array/output_test/visibilities.fits +# Test output: tests write results into output_test/ dirs and read them back. +# Never track them -- a change to the autonerves FITS writer would otherwise +# rewrite a committed binary and dirty every contributor's tree (PyAutoArray#483). +test_autoarray/**/output_test/ test_autoarray/dataset/plot/files/ test_autoarray/fit/plot/files/ test_autoarray/structures/arrays/one_d/files/array/ diff --git a/test_autoarray/dataset/files/array/output_test/noise_map.fits b/test_autoarray/dataset/files/array/output_test/noise_map.fits deleted file mode 100644 index 73d09cbd9b22d215d6cb3eac76b2534b75dcb688..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIuK?{N~7{>9A9s3CH7l_EBTVSEVphVDv*Odw$++te?zkS0BcbMcc=-ENH@$zT< zGImMNG0~npE2kCRq^PB8H5o}KmS?057bRDvXWm{NS)Q`O+gt9ow#Sv?9hKa0GTpuM zSBBfCV|TWss#+cy@WhXq1G5WgLCjz8bY zhqH5jN{KcUS%T(t)vDH}wd6D%nc!rdRHZa!WZoa`naEiY?akIJ-;>73j!Nkyx$aiQ zEB$G<)Pu<%~Wk}bra?@7IHd@&}GT4RQ;!STk7#z6`z2tknG&_vE8DkKD o00bZa0SG_<0>2R0PA6e~`hHgMga8B}009U<00Izzz<&!o0B=!(U;qFB diff --git a/test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits b/test_autoarray/dataset/files/arrays/output_test/background_sky_map.fits deleted file mode 100644 index d394dd47548f515c2c6920fd554f43d8614f76aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIuK?{N~7{>8FNQd_eL}bw|sK{VYB5Vh*D-}Gr#kLN9`^F;lus|pX;@Lsxc==C$ zoSpMiO0=QK5;Ui)R<$;*C8z1g1SjjHDy1nS^ZsbhM9zw6Z?<0fo-{^wR7xkwb+;;B z=})s=!MOj7{$JvI>fT-|L%M#Io3>K6(aQFb!7lU`Z+gqY;K*(0CEx3%*8FM#uLHL}bw|sK{VYB5Vh*D-}Gr#kLN9`^F;lus|pX;@Lsxc==C$ zoSpMiO0=QK5;Ui)R<$;*C8z1g1SjjHDy1nS^ZsbhM9zw6Z?<0fo-{^wR7xkwb+;;B z=})s=!MOj7{$JvI>fT-|L%M#Io3>K6(aQFb!7lU`Z+gqY;K*(0CEx3%*<)Pu<#cWk}bra?@7IHd@&}GT4RQ{7r8$7#z6`z2tknG~1878DkKD o00bZa0SG_<0>2R0+$Uju`hHgMga8B}009U<00Izzz<&!o0HkV)Hvj+t diff --git a/test_autoarray/dataset/files/arrays/output_test/noise_map.fits b/test_autoarray/dataset/files/arrays/output_test/noise_map.fits deleted file mode 100644 index bab8564c158560be41971b05bdd2aa91d7c9a23c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIuK?{N~7{>9AeT?@DL}bw|sK{VYB5Vh*D-}Gr#kLN9`^F;lus|pX;@Lsxc==C$ zoSpMiO0=QK5;Ui)R<$;*C8z1g1SjjHDy1nS^ZsbhM9zw6Z?<0fo-{^wR7xkwb+;;B z=})s=!MOj7{$JvI>fT-|L%M#Io3>K6(aQFb!7lU`Z+gqY;K*(0CEx3%*CV|TWss#+cy@WhXq1G5WgLCjz8bY zhqH5jN{KcUS%T(t)vDH}wd6D%nc!rdRHZa!WZoa`naEiY?akIJ-;>73j!Nkyx$aiQ zEB$G<)Pu<%~Wk}bra?@7IHd@&}GT4RQ;!STk7#z6`z2tknG&_vE8DkKD o00bZa0SG_<0>2R0PA6e~`hHgMga8B}009U<00Izzz<&!o0ROy#ga7~l diff --git a/test_autoarray/dataset/files/arrays/output_test/psf.fits b/test_autoarray/dataset/files/arrays/output_test/psf.fits deleted file mode 100644 index db4a4cae7ffe2af99ea12fb0d688a35295738fbc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIuK?}kl7{>8F%KHT(TG1`2Xn{~;upM@_bg+XOYKMLMWEI=NU{Dam<3%Sgf5)$2 zr~H@_ttqlfn$gAR+F0et8#=JEAm_Oj+=|G2xZ1HYXH~Q}T`fb8TgzJ#+;j5nRmLm* zZMLmg5k8~;mxP|ask5|X>Q}i@QoF`z*GC4Yt~YbtBMq#YE_?MqD%KMH5M*vbXjTJfz5aafGq$N=`1? z)9~~0_v0wJEb|QD0f?jF2DaYqd}up}9_CUj=%R782{n<&t0$>TS&_W!`#a>B5X>HG z6Ai@uyQL|I+d@=Q;V0Q|iahtxzS#hN_e*YC>$=9f?f@A~i8uL!cRL6kIVRrpay*o$ zp2eE_-^plvWT`={=T#TutzP6p7G%HiDgAmL+3zHtT8ccM2~FXrhIPTa+wj#cW`cM>fC)*Z><~18jf|06czQrE~7Pr|^>vumLu} Q2G{@_U;}J`4g7BdKUJuj=l}o! diff --git a/test_autoarray/structures/arrays/files/output_test/array.fits b/test_autoarray/structures/arrays/files/output_test/array.fits deleted file mode 100644 index 7f3001a57fe8170c952244016b87ed9e4a5ea192..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIu!3u&f9LMn<<^KW^S#*miG8mKy^Wb$g1rKhqt%GmfBQzGFhXq1G5WgLCjz8bY zhqF_DOo`SMSq07LqE)R;YsqOku!56yLP=p{WZoa`Sdp_b+MBMHz9)<)Pu<#cWk}bra?@7IHd@&}GT4RQ{7r8$7#z6`z2tknG~1878DkKD o00bZa0SG_<0>2R0+$Uju`hHgMga8B}009U<00Izzz<&!o0HkV)Hvj+t diff --git a/test_autoarray/structures/arrays/files/output_test/masked_array.fits b/test_autoarray/structures/arrays/files/output_test/masked_array.fits deleted file mode 100644 index 7f3001a57fe8170c952244016b87ed9e4a5ea192..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5760 zcmeIu!3u&f9LMn<<^KW^S#*miG8mKy^Wb$g1rKhqt%GmfBQzGFhXq1G5WgLCjz8bY zhqF_DOo`SMSq07LqE)R;YsqOku!56yLP=p{WZoa`Sdp_b+MBMHz9)<)Pu<#cWk}bra?@7IHd@&}GT4RQ{7r8$7#z6`z2tknG~1878DkKD o00bZa0SG_<0>2R0+$Uju`hHgMga8B}009U<00Izzz<&!o0HkV)Hvj+t diff --git a/test_autoarray/structures/arrays/files/output_test/values_test.dat b/test_autoarray/structures/arrays/files/output_test/values_test.dat deleted file mode 100644 index 32ecc300a..000000000 --- a/test_autoarray/structures/arrays/files/output_test/values_test.dat +++ /dev/null @@ -1 +0,0 @@ -[6.0, 7.0, 8.0] \ No newline at end of file diff --git a/test_autoarray/structures/arrays/files/values/output_test/values_test.dat b/test_autoarray/structures/arrays/files/values/output_test/values_test.dat deleted file mode 100644 index 32ecc300a..000000000 --- a/test_autoarray/structures/arrays/files/values/output_test/values_test.dat +++ /dev/null @@ -1 +0,0 @@ -[6.0, 7.0, 8.0] \ No newline at end of file diff --git a/test_autoarray/structures/arrays/test_uniform_1d.py b/test_autoarray/structures/arrays/test_uniform_1d.py index 06c2a92b7..f9e6540fb 100644 --- a/test_autoarray/structures/arrays/test_uniform_1d.py +++ b/test_autoarray/structures/arrays/test_uniform_1d.py @@ -9,8 +9,6 @@ fits_path = Path(__file__).resolve().parent / "files" / "array_1d" -test_data_path = Path(__file__).resolve().parent / "files" / "array" / "output_test" - def create_fits( fits_path, @@ -154,25 +152,20 @@ def test__from_fits__4_element_fits__header_bitpix_is_minus_64(): clean_fits(fits_path=fits_path) -def test__output_to_fits__ones_array__fits_file_has_correct_values_and_header(): +def test__output_to_fits__ones_array__fits_file_has_correct_values_and_header(tmp_path): arr = aa.Array1D.ones(shape_native=(3,), pixel_scales=1.0) - if test_data_path.exists(): - shutil.rmtree(test_data_path) - - os.makedirs(test_data_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=arr.native.array.astype("float"), file_path=test_data_path / "array.fits", header_dict=arr.mask.header_dict) + output_to_fits(values=arr.native.array.astype("float"), file_path=tmp_path / "array.fits", header_dict=arr.mask.header_dict) array_from_out = aa.Array1D.from_fits( - file_path=test_data_path / "array.fits", hdu=0, pixel_scales=1.0 + file_path=tmp_path / "array.fits", hdu=0, pixel_scales=1.0 ) assert (array_from_out.native == np.ones((3,))).all() header_load = aa.header_obj_from( - file_path=test_data_path / "array.fits", hdu=0 + file_path=tmp_path / "array.fits", hdu=0 ) assert header_load["PIXSCA"] == 1.0 diff --git a/test_autoarray/structures/arrays/test_uniform_2d.py b/test_autoarray/structures/arrays/test_uniform_2d.py index 2cfa4aa51..2540c0c8e 100644 --- a/test_autoarray/structures/arrays/test_uniform_2d.py +++ b/test_autoarray/structures/arrays/test_uniform_2d.py @@ -1,10 +1,8 @@ from astropy.io import fits -import os from pathlib import Path import numpy as np import pytest -import shutil import autoarray as aa @@ -191,24 +189,20 @@ def test__from_yx_and_values__3x2_grid__native_matches_expected_pixel_layout(): assert (array_2d.native == np.array([[3.0, 2.0], [6.0, 4.0], [5.0, 1.0]])).all() -def test__output_to_fits__3x3_ones__fits_file_has_ones_and_correct_pixel_scale_header(): +def test__output_to_fits__3x3_ones__fits_file_has_ones_and_correct_pixel_scale_header( + tmp_path, +): files_path = Path(__file__).resolve().parent / "files" array_2d = aa.Array2D.from_fits( file_path=files_path / "3x3_ones.fits", hdu=0, pixel_scales=1.0 ) - output_test_path = files_path / "array" / "output_test" - if output_test_path.exists(): - shutil.rmtree(output_test_path) - - os.makedirs(output_test_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=array_2d.native.array.astype("float"), file_path=output_test_path / "array.fits", header_dict=array_2d.mask.header_dict) + output_to_fits(values=array_2d.native.array.astype("float"), file_path=tmp_path / "array.fits", header_dict=array_2d.mask.header_dict) array_from_fits = aa.Array2D.from_fits( - file_path=output_test_path / "array.fits", hdu=0, pixel_scales=1.0 + file_path=tmp_path / "array.fits", hdu=0, pixel_scales=1.0 ) assert (array_from_fits.native == np.ones((3, 3))).all() diff --git a/test_autoarray/structures/test_visibilities.py b/test_autoarray/structures/test_visibilities.py index 782651ba0..1e2c3507c 100644 --- a/test_autoarray/structures/test_visibilities.py +++ b/test_autoarray/structures/test_visibilities.py @@ -1,8 +1,6 @@ -import os from pathlib import Path import numpy as np import pytest -import shutil import autoarray as aa from autoarray.structures import visibilities as vis @@ -86,25 +84,18 @@ def test__from_fits__makes_visibilities_without_other_inputs(): assert (visibilities.slim == np.array([2.0 + 2.0j, 2.0 + 2.0j, 2.0 + 2.0j])).all() -def test__output_to_fits(): +def test__output_to_fits(tmp_path): files_path = Path(__file__).resolve().parent / "files" visibilities = aa.Visibilities.from_fits( file_path=files_path / "3x2_ones.fits", hdu=0 ) - output_test_path = files_path / "output_test" - - if output_test_path.exists(): - shutil.rmtree(output_test_path) - - os.makedirs(output_test_path) - from autonerves.fitsable import output_to_fits - output_to_fits(values=visibilities.in_array, file_path=output_test_path / "data.fits") + output_to_fits(values=visibilities.in_array, file_path=tmp_path / "data.fits") visibilities_from_out = aa.Visibilities.from_fits( - file_path=output_test_path / "data.fits", hdu=0 + file_path=tmp_path / "data.fits", hdu=0 ) assert ( visibilities_from_out.slim == np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j])