Skip to content

Commit

Permalink
use tmp_path in tests that create temporary files (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett authored Aug 21, 2024
1 parent 65a5a89 commit 7996733
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 224 deletions.
7 changes: 2 additions & 5 deletions tests/test_airglow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os


def test_find_airglow_limits():
def test_find_airglow_limits(tmp_path):
"""
unit test for find_airglow_limits()
test ran
Expand All @@ -23,7 +23,7 @@ def test_find_airglow_limits():
inf = {"obstype": "SPECTROSCOPIC", "cenwave": 1055, "aperture": "PSA", "detector": "FUV",
"opt_elem": "G130M", "segment": "FUVA"}
seg = ["FUVA", "FUVB"]
disptab = create_disptab_file('49g17153l_disp.fits')
disptab = create_disptab_file(str(tmp_path / '49g17153l_disp.fits'))
airglow_lines = ["Lyman_alpha", "N_I_1200", "O_I_1304", "O_I_1356", "N_I_1134"]
actual_pxl = [
[], [], (15421.504705213156, 15738.02214190493), (8853.838672375898, 9135.702216258482)]
Expand All @@ -39,6 +39,3 @@ def test_find_airglow_limits():
# Verify
for i in range(len(actual_pxl)):
assert actual_pxl[i] == test_pxl[i]

# Cleanup
os.remove(disptab)
13 changes: 3 additions & 10 deletions tests/test_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from generate_tempfiles import create_count_file


def test_avg_image():
def test_avg_image(tmp_path):
"""
tests avg_image() in average.py
explanation of the test
Expand All @@ -19,10 +19,8 @@ def test_avg_image():
pass if expected == actual fail otherwise.
"""
# Setup
infile = ["test_count1.fits", "test_count2.fits"]
outfile = "test_output.fits"
if os.path.exists(outfile):
os.remove(outfile) # avoid file exists error
infile = [str(tmp_path / "test_count1.fits"), str(tmp_path / "test_count2.fits")]
outfile = str(tmp_path / "test_output.fits")
create_count_file(infile[0])
create_count_file(infile[1])
inhdr1, inhdr2 = fits.open(infile[0]), fits.open(infile[1])
Expand All @@ -35,8 +33,3 @@ def test_avg_image():
for (i, j, k) in zip(inhdr1[1].header, inhdr2[1].header, out_hdr[1].header):
assert i == j == k
np.testing.assert_array_equal((inhdr1[1].data + inhdr1[1].data) / 2, out_hdr[1].data)

# Cleanup
for tempfile in infile:
os.remove(tempfile)
os.remove(outfile)
Loading

0 comments on commit 7996733

Please sign in to comment.