Skip to content

Commit 4908465

Browse files
use tmp_path in tests that create temporary files
1 parent 65a5a89 commit 4908465

File tree

5 files changed

+144
-224
lines changed

5 files changed

+144
-224
lines changed

tests/test_airglow.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44

55

6-
def test_find_airglow_limits():
6+
def test_find_airglow_limits(tmp_path):
77
"""
88
unit test for find_airglow_limits()
99
test ran
@@ -23,7 +23,7 @@ def test_find_airglow_limits():
2323
inf = {"obstype": "SPECTROSCOPIC", "cenwave": 1055, "aperture": "PSA", "detector": "FUV",
2424
"opt_elem": "G130M", "segment": "FUVA"}
2525
seg = ["FUVA", "FUVB"]
26-
disptab = create_disptab_file('49g17153l_disp.fits')
26+
disptab = create_disptab_file(str(tmp_path / '49g17153l_disp.fits'))
2727
airglow_lines = ["Lyman_alpha", "N_I_1200", "O_I_1304", "O_I_1356", "N_I_1134"]
2828
actual_pxl = [
2929
[], [], (15421.504705213156, 15738.02214190493), (8853.838672375898, 9135.702216258482)]
@@ -39,6 +39,3 @@ def test_find_airglow_limits():
3939
# Verify
4040
for i in range(len(actual_pxl)):
4141
assert actual_pxl[i] == test_pxl[i]
42-
43-
# Cleanup
44-
os.remove(disptab)

tests/test_average.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from generate_tempfiles import create_count_file
88

99

10-
def test_avg_image():
10+
def test_avg_image(tmp_path):
1111
"""
1212
tests avg_image() in average.py
1313
explanation of the test
@@ -19,10 +19,8 @@ def test_avg_image():
1919
pass if expected == actual fail otherwise.
2020
"""
2121
# Setup
22-
infile = ["test_count1.fits", "test_count2.fits"]
23-
outfile = "test_output.fits"
24-
if os.path.exists(outfile):
25-
os.remove(outfile) # avoid file exists error
22+
infile = [str(tmp_path / "test_count1.fits"), str(tmp_path / "test_count2.fits")]
23+
outfile = str(tmp_path / "test_output.fits")
2624
create_count_file(infile[0])
2725
create_count_file(infile[1])
2826
inhdr1, inhdr2 = fits.open(infile[0]), fits.open(infile[1])
@@ -35,8 +33,3 @@ def test_avg_image():
3533
for (i, j, k) in zip(inhdr1[1].header, inhdr2[1].header, out_hdr[1].header):
3634
assert i == j == k
3735
np.testing.assert_array_equal((inhdr1[1].data + inhdr1[1].data) / 2, out_hdr[1].data)
38-
39-
# Cleanup
40-
for tempfile in infile:
41-
os.remove(tempfile)
42-
os.remove(outfile)

0 commit comments

Comments
 (0)