Skip to content

Commit

Permalink
Added test for occreject_exam
Browse files Browse the repository at this point in the history
  • Loading branch information
m-dallas committed Jan 8, 2025
1 parent ee1045c commit 7260942
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions tests/test_ocrreject_exam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from stistools.ocrreject_exam import ocrreject_exam
from .resources import BaseSTIS
import numpy as np
import os
import pytest


Expand All @@ -8,7 +10,6 @@
class TestOcrrejectExam(BaseSTIS):

input_loc = 'ocrreject_exam'
ref_loc = 'ocrreject_exam/ref'

input_list = ["odvkl1040_flt.fits", "odvkl1040_sx1.fits"]

Expand All @@ -18,17 +19,28 @@ class TestOcrrejectExam(BaseSTIS):
def test_ocrrject_exam(self):
"""
This regression test runs the task on the known problematic dataset odvkl1040.
The resulting output dictionary is compared to a
reference file using 'FITSDIFF'. COULD I JUST PULL OUT THE KEY/VAL PAIRS AND CHECK IF THEY'RE SIMILAR?
The resulting output dictionary is compared to the known values for odvkl1040.
"""

# Prepare input files.
for filename in self.input_list:
self.get_input_file("input", filename)
local_file = self.get_data("input", filename)

expected_output = {'rootname': 'odvkl1040',
'extr_fracs': np.array([0.31530762, 0.32006836]),
'outside_fracs': np.array([0.00884673, 0.00810278]),
'ratios': np.array([35.64113429, 39.50106762]),
'avg_extr_frac': 0.31768798828125,
'avg_outside_frac': 0.008474755474901575,
'avg_ratio': 37.486389928547126}

# Run ocrreject_exam
ocrreject(self.input_file_string, output="ocrreject_lev3_crj.fits")
resulting_output = ocrreject_exam('odvkl1040', data_dir=os.path.dirname(local_file))

# Compare results
outputs = [("ocrreject_lev3_crj.fits", "ocrreject_lev3_crj_ref.fits")]
self.compare_outputs(outputs)
assert len(resulting_output) == 1, "Output is not a list of only one dictionary"

resulting_output = resulting_output[0]

assert set(resulting_output) == set(expected_output), "Not all created keys match"

for key in expected_output:
assert resulting_output[key] == pytest.approx(expected_output[key]), f"{key} failed"

0 comments on commit 7260942

Please sign in to comment.