Skip to content

Commit

Permalink
Add more regtests (#247)
Browse files Browse the repository at this point in the history
* Added regression tests

* Missed one temp_path usage so temp file was getting left behind

* Fix Python version
  • Loading branch information
stscirij authored Aug 28, 2024
1 parent 0079eaf commit c512a57
Show file tree
Hide file tree
Showing 20 changed files with 649 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "calcos"
description = "Calibration software for COS (Cosmic Origins Spectrograph)"
requires-python = ">=3.9"
requires-python = ">=3.9,<3.13"
authors = [
{ name = "Phil Hodge", email="[email protected]" },
{ name = "Robert Jedrzejewski" },
Expand Down
7 changes: 5 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ def get_input_files(self, filenames):
file)
# If file is an association table, download raw files specified in the table
if file.endswith('_asn.fits'):
asn_raws = raw_from_asn(file, '_rawtag_a.fits')
asn_raws += raw_from_asn(file, '_rawtag_b.fits')
if self.detector == 'nuv':
asn_raws = raw_from_asn(file, '_rawtag.fits')
else:
asn_raws = raw_from_asn(file, '_rawtag_a.fits')
asn_raws += raw_from_asn(file, '_rawtag_b.fits')
for raw in asn_raws: # Download RAWs in ASN.
get_bigdata('scsb-calcos', self.env, self.detector, 'input',
raw)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_acq_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Tests for COS/NUV ACQ/IMAGE."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestNUVCQIMAGE(BaseCOS):
detector = 'nuv'

def test_fuv_acq_image(self):
"""
FUV COS regression test
"""
files_to_download = ['ldji01ggq_rawacq.fits',
'ldji01ggq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'ldji01ggq_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# Compare results.
# The first outroot is the output from whole ASN,
# the rest are individual members.
outroots = ['ldji01ggq']
outputs = []
for outroot in outroots:
for sfx in ('counts', 'flt'):
fname = '{}_{}.fits'.format(outroot, sfx)
outputs.append((fname, 'ref_' + fname))
self.compare_outputs(outputs, rtol=1e-7)

31 changes: 31 additions & 0 deletions tests/test_acq_peakd_both.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for COS/BOTH ACQ/PEAKD."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestBOTHACQPEAKD(BaseCOS):
detector = 'fuv'

def test_both_acq_peakd(self):
"""
FUV COS regression test
"""
files_to_download = ['ld7y02rrq_rawacq.fits',
'ld7y02rrq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'ld7y02rrq_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# No need to compare results as this test doesn't
# produce any products. We are just testing that the
# code runs to completion
31 changes: 31 additions & 0 deletions tests/test_acq_peakd_fuva.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for COS/FUVA ACQ/PEAKD."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestFUVAACQPEAKD(BaseCOS):
detector = 'fuv'

def test_fuva_acq_peakd(self):
"""
FUV COS regression test
"""
files_to_download = ['lbx503kfq_rawacq.fits',
'lbx503kfq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'lbx503kfq_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# No need to compare results as this test doesn't
# product any products. We are just testing that the
# code runs to completion
31 changes: 31 additions & 0 deletions tests/test_acq_peakd_nuv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for COS/NUV ACQ/PEAKD."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestNUVACQPEAKD(BaseCOS):
detector = 'nuv'

def test_nuv_acq_peakd(self):
"""
FUV COS regression test
"""
files_to_download = ['la8q99l7q_rawacq.fits',
'la8q99l7q_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la8q99l7q_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# No need to compare results as this test doesn't
# product any products. We are just testing that the
# code runs to completion
31 changes: 31 additions & 0 deletions tests/test_acq_peakxd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for COS/FUV ACQ/PEAKXD."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestFUVACQPEAKXD(BaseCOS):
detector = 'fuv'

def test_fuv_acq_peakxd(self):
"""
FUV COS regression test
"""
files_to_download = ['la9t01naq_rawacq.fits',
'la9t01naq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la9t01naq_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# No need to compare results as this test doesn't
# product any products. We are just testing that the
# code runs to completion
31 changes: 31 additions & 0 deletions tests/test_acq_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Tests for COS/FUV ACQ/SEARCH."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestFUVACQSEARCH(BaseCOS):
detector = 'fuv'

def test_fuv_acq_search(self):
"""
FUV COS regression test
"""
files_to_download = ['la9t01n9q_rawacq.fits',
'la9t01n9q_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la9t01n9q_rawacq.fits'
# Run CALCOS
calcos.calcos(input_file)

# No need to compare results as this test doesn't
# product any products. We are just testing that the
# code runs to completion
2 changes: 1 addition & 1 deletion tests/test_cosutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def test_get_switch(tmp_path):


def test_temp_pulse_height_range(tmp_path):
filename = "pulseHeightRef.fits"
filename = str(tmp_path / "pulseHeightRef.fits")
generate_fits_file(filename)
true_pha_value = 4
fits.setval(filename, "pharange", value=true_pha_value, ext=0)
Expand Down
44 changes: 44 additions & 0 deletions tests/test_nuv_sci_g185m.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for COS/NUV G185M sci data."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestNUVSciG185M(BaseCOS):
detector = 'nuv'

def test_nuv_sci_g185m(self):
"""
COS regression test
"""
files_to_download = ['la8q99050_asn.fits',
'la8q99jbq_rawtag.fits',
'la8q99jbq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la8q99050_asn.fits'
# Run CALCOS
calcos.calcos(input_file)

# Compare results.
# The first outroot is the output from whole ASN,
# the rest are individual members.
outroots = ['la8q99050', 'la8q99jbq']
outputs = []
for sfx in ['x1dsum', 'x1dsum3']:
fname = f'{outroots[0]}_{sfx}.fits'
comparison_name = 'ref_' + fname
outputs.append((fname, comparison_name))
for outroot in outroots[1:]:
for sfx in ('corrtag', 'counts',
'flt', 'lampflash', 'x1d'):
fname = '{}_{}.fits'.format(outroot, sfx)
outputs.append((fname, 'ref_' + fname))
self.compare_outputs(outputs, rtol=1e-7)
44 changes: 44 additions & 0 deletions tests/test_nuv_sci_g230l.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for COS/NUV G230L sci data."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestNUVSciG230L(BaseCOS):
detector = 'nuv'

def test_nuv_sci_g230l(self):
"""
COS regression test
"""
files_to_download = ['la8p93030_asn.fits',
'la8p93a7q_rawtag.fits',
'la8p93a7q_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la8p93030_asn.fits'
# Run CALCOS
calcos.calcos(input_file)

# Compare results.
# The first outroot is the output from whole ASN,
# the rest are individual members.
outroots = ['la8p93030', 'la8p93a7q']
outputs = []
for sfx in ['x1dsum', 'x1dsum3']:
fname = f'{outroots[0]}_{sfx}.fits'
comparison_name = 'ref_' + fname
outputs.append((fname, comparison_name))
for outroot in outroots[1:]:
for sfx in ('corrtag', 'counts',
'flt', 'lampflash', 'x1d'):
fname = '{}_{}.fits'.format(outroot, sfx)
outputs.append((fname, 'ref_' + fname))
self.compare_outputs(outputs, rtol=1e-7)
44 changes: 44 additions & 0 deletions tests/test_nuv_sci_g285m.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for COS/NUV G285M sci data."""

import pytest

import calcos
from helpers import BaseCOS


# TODO: Mark this as slow when there are faster tests added for CI tests
# so that this only runs in nightly tests.
@pytest.mark.slow
class TestNUVSciG285M(BaseCOS):
detector = 'nuv'

def test_nuv_sci_g285m(self):
"""
COS regression test
"""
files_to_download = ['la8q99030_asn.fits',
'la8q99ixq_rawtag.fits',
'la8q99ixq_spt.fits']

# Prepare input files.
self.get_input_files(files_to_download)

input_file = 'la8q99030_asn.fits'
# Run CALCOS
calcos.calcos(input_file)

# Compare results.
# The first outroot is the output from whole ASN,
# the rest are individual members.
outroots = ['la8q99030', 'la8q99ixq']
outputs = []
for sfx in ['x1dsum', 'x1dsum3']:
fname = f'{outroots[0]}_{sfx}.fits'
comparison_name = 'ref_' + fname
outputs.append((fname, comparison_name))
for outroot in outroots[1:]:
for sfx in ('corrtag', 'counts',
'flt', 'lampflash', 'x1d'):
fname = '{}_{}.fits'.format(outroot, sfx)
outputs.append((fname, 'ref_' + fname))
self.compare_outputs(outputs, rtol=1e-7)
Loading

0 comments on commit c512a57

Please sign in to comment.