Skip to content

Commit

Permalink
Merge pull request #158 from spacetelescope/is_test_coverage
Browse files Browse the repository at this point in the history
Adding some new tests (HETC-885)
  • Loading branch information
isaacspitzer authored Jul 23, 2024
2 parents 54e9e2a + f10bd26 commit a23d65f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pysynphot/test/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
from numpy.testing import assert_allclose, assert_array_equal

import pysynphot

from ..observation import Observation
from ..obsbandpass import ObsBandpass
from ..spectrum import ArraySourceSpectrum, Box, FlatSpectrum
Expand Down Expand Up @@ -127,6 +129,49 @@ def test_not_allowed(self):
with pytest.raises(NotImplementedError):
self.obs + other

def test_fluxcheck(self):
try:
self.obs._fluxcheck(self.obs.flux.sum())
except ValueError:
pytest.fail('Unexpected ValueError in the _fluxcheck method.')
with pytest.raises(ValueError) as e_info:
self.obs._fluxcheck(0.0)
with pytest.raises(ValueError) as e_info:
self.obs._fluxcheck(-10.0)
with pytest.raises(ValueError) as e_info:
self.obs._fluxcheck(np.nan)
with pytest.raises(ValueError) as e_info:
self.obs._fluxcheck(np.inf)

def test_as_spectrum(self):
s = self.obs.as_spectrum()
assert isinstance(s, ArraySourceSpectrum)

def test_check_overlap(self):
sp1 = FlatSpectrum(1, fluxunits='counts')
sp2 = FlatSpectrum(1, fluxunits='counts')
# Comparisons with analytic spectra will always return full
assert pysynphot.observation.check_overlap(sp1, sp2) == 'full'

# Check that 2 non-analytic spectra are the same
w1 = np.array([10., 100., 1000.])
w2 = np.array([10., 100., 1000.])
f = np.array([1., 1., 1.])
sp1 = ArraySourceSpectrum(w1, f)
sp2 = ArraySourceSpectrum(w2, f)
assert pysynphot.observation.check_overlap(sp1, sp2) == 'full'

# Check for partial overlap with 2 non-analytic spectra
w2 = np.array([100., 1000., 5000.])
sp2 = ArraySourceSpectrum(w2, f)
assert pysynphot.observation.check_overlap(sp1, sp2) == 'partial'
assert pysynphot.observation.check_overlap(sp2, sp1) == 'partial'

# Check for no overlap with 2 non-analytic spectra
w2 = np.array([5000., 6000., 7000.])
sp2 = ArraySourceSpectrum(w2, f)
assert pysynphot.observation.check_overlap(sp1, sp2) == 'none'


@pytest.mark.remote_data
def test_no_neg_leak():
Expand Down

0 comments on commit a23d65f

Please sign in to comment.