Skip to content

Commit a731948

Browse files
fix issues introduced in amendment to spacetelescope#243
1 parent 7996733 commit a731948

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

tests/test_cosutil.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
import time
5+
from pathlib import Path
56

67
import numpy as np
78
import pytest
@@ -113,15 +114,16 @@ def test_concat_arrays():
113114

114115
def test_update_filename(tmp_path):
115116
# Setup
116-
filename = str(tmp_path / "update_filename")
117+
path = tmp_path / "update_filename.fits"
118+
filename = str(path)
117119
generate_fits_file(filename)
118120
before_update_hdr = fits.open(filename, mode="update")
119121
# Test
120-
cosutil.updateFilename(before_update_hdr[0].header, filename)
122+
cosutil.updateFilename(before_update_hdr[0].header, path.stem)
121123
before_update_hdr.close()
122124
after_update_hdr = fits.open(filename)
123125
# Verity
124-
assert filename == after_update_hdr[0].header["filename"]
126+
assert path.stem == after_update_hdr[0].header["filename"]
125127
after_update_hdr.close()
126128

127129

@@ -364,8 +366,8 @@ def test_change_segment(tmp_path):
364366
filename2 = str(tmp_path / "testfits_b.fits")
365367
filename3 = str(tmp_path / "testfits.fits")
366368
# Expected
367-
fname1 = filename1
368-
fname2 = filename2
369+
fname1 = filename2
370+
fname2 = filename1
369371
fname3 = filename3
370372
# Test
371373
test_name1 = cosutil.changeSegment(filename1, "FUV", "FUVB")
@@ -524,8 +526,9 @@ def test_rename_file(tmp_path):
524526

525527
def test_del_corrtag_wcs(tmp_path):
526528
# Setup
527-
generate_fits_file(str(tmp_path / "del_corrtagWCS.fits"))
528-
thdr = fits.getheader("del_corrtagWCS.fits", 3)
529+
filename = str(tmp_path / "del_corrtagWCS.fits")
530+
generate_fits_file(filename)
531+
thdr = fits.getheader(filename, 3)
529532
tkey = ["TCTYP2", "TCRVL2", "TCRPX2", "TCDLT2", "TCUNI2", "TC2_2", "TC2_3",
530533
"TCTYP3", "TCRVL3", "TCRPX3", "TCDLT3", "TCUNI3", "TC3_2", "TC3_3"]
531534
# Test
@@ -776,16 +779,19 @@ def test_segment_specific_keyword():
776779

777780

778781
def test_find_ref_file(tmp_path):
779-
generate_fits_file(str(tmp_path / "test.fits"))
780-
fits.setval("wrong_file.fits", 'FILETYPE', value='FLAT FIELD REFERENCE IMAGE')
782+
filename = str(tmp_path / "test.fits")
783+
wrong_filename = str(tmp_path / "wrong_file.fits")
784+
generate_fits_file(filename)
785+
generate_fits_file(wrong_filename)
786+
fits.setval(wrong_filename, 'FILETYPE', value='FLAT FIELD REFERENCE IMAGE')
781787
# Missing
782788
ref1 = {"keyword": "FLATFILE", "filename": "test_flt.fits", "calcos_ver": "3.0",
783789
"min_ver": "2.2", "filetype": "FLAT FIELD REFERENCE IMAGE"}
784790
# Bad version
785-
ref2 = {"keyword": "FLATFILE", "filename": "test.fits", "calcos_ver": "2.21",
791+
ref2 = {"keyword": "FLATFILE", "filename": filename, "calcos_ver": "2.21",
786792
"min_ver": "3.3", "filetype": "FLAT FIELD REFERENCE IMAGE"}
787793
# Wrong file
788-
ref3 = {"keyword": "FLATFILE", "filename": "wrong_file.fits", "calcos_ver": "3.0",
794+
ref3 = {"keyword": "FLATFILE", "filename": wrong_filename, "calcos_ver": "3.0",
789795
"min_ver": "2.3", "filetype": "IMAGE"}
790796
missing1 = {}
791797
missing2 = {}
@@ -798,8 +804,8 @@ def test_find_ref_file(tmp_path):
798804
bad_ver3 = {}
799805
# Actual values
800806
actual_missing = {"FLATFILE": "test_flt.fits"}
801-
actual_bad_ver = {"FLATFILE": ("test.fits", " the reference file must be at least version 3.3")}
802-
actual_wrong_ver = {'FLATFILE': ('wrong_file.fits', 'IMAGE')}
807+
actual_bad_ver = {"FLATFILE": (filename, " the reference file must be at least version 3.3")}
808+
actual_wrong_ver = {'FLATFILE': (wrong_filename, 'IMAGE')}
803809
# Test
804810
cosutil.findRefFile(ref1, missing1, wrong_f1, bad_ver1)
805811
cosutil.findRefFile(ref2, missing2, wrong_f2, bad_ver2)
@@ -832,7 +838,7 @@ def test_get_pedigree(tmp_path):
832838
refkey = "statflag"
833839
filename = str(tmp_path / "test_flt.file")
834840
generate_fits_file(filename)
835-
err_msg = "Warning: STATFLAG test_flt.file is a dummy file\n" \
841+
err_msg = f"Warning: STATFLAG {filename} is a dummy file\n" \
836842
" so PERFORM will not be done.\n"
837843
# Test
838844
pedgr1 = cosutil.getPedigree(switch, refkey, filename)

tests/test_shiftfile.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import os
2-
31
from calcos import shiftfile
42

53
def create_shift_file(filename):
64
# Create the shift file for use in tests
7-
shift_file = "shift_file.txt"
8-
with open(shift_file, "w") as file:
5+
with open(filename, "w") as file:
96
file.write("#dataset\tfpoffset\tflash #\tstripe\tshift1\tshift2\n")
107
for i in range(10):
118
if i % 3 == 0:

0 commit comments

Comments
 (0)