Skip to content

Commit

Permalink
gh-238: utilise tmp_path correctly in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Sep 19, 2024
1 parent 30f86a6 commit 5bd091c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ build
dist
.env
.coverage*
*.Fits
23 changes: 9 additions & 14 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ def _test_append(fits, data, names):
def test_basic_write(tmp_path):
import fitsio

d = tmp_path / "sub"
d.mkdir()
filename_gfits = "gfits.fits" # what GLASS creates
filename_tfits = "tfits.fits" # file created on the fly to test against

with user.write_catalog(d / filename_gfits, ext="CATALOG") as out, fitsio.FITS(
d / filename_tfits, "rw", clobber=True
) as myFits:
with user.write_catalog(
tmp_path / filename_gfits, ext="CATALOG"
) as out, fitsio.FITS(tmp_path / filename_tfits, "rw", clobber=True) as myFits:
for i in range(0, my_max):
array = np.arange(i, i + 1, delta) # array of size 1/delta
array2 = np.arange(i + 1, i + 2, delta) # array of size 1/delta
Expand All @@ -48,8 +46,8 @@ def test_basic_write(tmp_path):
names = ["RA", "RB"]
_test_append(myFits, arrays, names)

with fitsio.FITS(d / filename_gfits) as g_fits, fitsio.FITS(
d / filename_tfits
with fitsio.FITS(tmp_path / filename_gfits) as g_fits, fitsio.FITS(
tmp_path / filename_tfits
) as t_fits:
glass_data = g_fits[1].read()
test_data = t_fits[1].read()
Expand All @@ -59,11 +57,8 @@ def test_basic_write(tmp_path):

@pytest.mark.skipif(not HAVE_FITSIO, reason="test requires fitsio")
def test_write_exception(tmp_path):
d = tmp_path / "sub"
d.mkdir()

try:
with user.write_catalog(d / filename, ext="CATALOG") as out:
with user.write_catalog(tmp_path / filename, ext="CATALOG") as out:
for i in range(0, my_max):
if i == except_int:
raise Exception("Unhandled exception")
Expand All @@ -74,7 +69,7 @@ def test_write_exception(tmp_path):
except Exception:
import fitsio

with fitsio.FITS(d / filename) as hdul:
with fitsio.FITS(tmp_path / filename) as hdul:
data = hdul[1].read()
assert data["RA"].size == except_int / delta
assert data["RB"].size == except_int / delta
Expand All @@ -94,6 +89,6 @@ def test_write_exception(tmp_path):
def test_out_filename(tmp_path):
import fitsio

fits = fitsio.FITS(filename, "rw", clobber=True)
fits = fitsio.FITS(tmp_path / filename, "rw", clobber=True)
writer = user._FitsWriter(fits)
assert writer.fits._filename == filename
assert writer.fits._filename == f"{tmp_path}/{filename}"

0 comments on commit 5bd091c

Please sign in to comment.