Skip to content

Commit

Permalink
Merge sherpa#2056 (DougBurke) - tests: fix fake_pha test failure on c…
Browse files Browse the repository at this point in the history
…rates

tests: fix fake_pha test failure on crates
  • Loading branch information
wmclaugh committed May 31, 2024
2 parents 9aef535 + 7829604 commit 578773a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
12 changes: 8 additions & 4 deletions sherpa/astro/ui/tests/test_astro_ui_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ def check_fit_stats():
# This test produces different results on macOS to Linux, hence
# the relaxed tolerances.
#
assert pl.gamma.val == pytest.approx(1.6870563856336693, rel=1e-5)
assert pl.ampl.val == pytest.approx(3.831373278007354e-05, rel=2e-5)
assert gal.nH.val == pytest.approx(0.24914805790330877, rel=3e-5)
assert ui.calc_stat() == pytest.approx(41.454087606314054, rel=1e-5)
assert pl.gamma.val == pytest.approx(1.6870563856336693,
rel=1.02e-5)
assert pl.ampl.val == pytest.approx(3.831373278007354e-05,
rel=2e-5)
assert gal.nH.val == pytest.approx(0.24914805790330877,
rel=3e-5)
assert ui.calc_stat() == pytest.approx(41.454087606314054,
rel=1e-5)


@requires_xspec
Expand Down
47 changes: 42 additions & 5 deletions sherpa/astro/ui/tests/test_astro_ui_utils_simulation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2020, 2021, 2022, 2023
# Copyright (C) 2020 - 2024
# Smithsonian Astrophysical Observatory
#
#
Expand Down Expand Up @@ -56,22 +56,43 @@ def test_fake_pha_no_rmf(idval, clean_astro_ui):
def test_fake_pha_missing_rmf(idval, clean_astro_ui, tmp_path):
"""Check we error out if RMF is not valid."""

from sherpa.astro import io

channels = np.arange(1, 4, dtype=np.int16)
counts = np.ones(3, dtype=np.int16)

ui.load_arrays(idval, channels, counts, ui.DataPHA)

rmf = tmp_path / 'rmf'
with pytest.raises(IOErr,
match=f"file '{rmf}' not found"):

# Wrap this so we don't repeat the logic below in the
# backend-specific code.
#
def call_fake():
ui.fake_pha(idval, None, str(rmf), 1000.0)

# The error message depends on the backend.
if io.backend.__name__ == "sherpa.astro.io.pyfits_backend":
with pytest.raises(IOErr,
match=f"file '{rmf}' not found"):
call_fake()

elif io.backend.__name__ == "sherpa.astro.io.crates_backend":
with pytest.raises(OSError,
match=f"File {rmf} does not exist"):
call_fake()

else:
assert False, "unknown backend"


@requires_fits
@pytest.mark.parametrize("idval", [None, 1, "faked"])
def test_fake_pha_missing_arf(idval, clean_astro_ui, tmp_path):
"""Check we error out if ARF is not valid."""

from sherpa.astro import io

channels = np.arange(1, 4, dtype=np.int16)
counts = np.ones(3, dtype=np.int16)

Expand All @@ -84,10 +105,26 @@ def test_fake_pha_missing_arf(idval, clean_astro_ui, tmp_path):

arf = tmp_path / 'arf'

with pytest.raises(IOErr,
match=f"file '{arf}' not found"):
# Wrap this so we don't repeat the logic below in the
# backend-specific code.
#
def call_fake():
ui.fake_pha(idval, str(arf), rmf, 1000.0)

# The error message depends on the backend.
if io.backend.__name__ == "sherpa.astro.io.pyfits_backend":
with pytest.raises(IOErr,
match=f"file '{arf}' not found"):
call_fake()

elif io.backend.__name__ == "sherpa.astro.io.crates_backend":
with pytest.raises(OSError,
match=f"File {arf} does not exist"):
call_fake()

else:
assert False, "unknown backend"


@pytest.mark.parametrize("idval", [None, 1, "faked"])
def test_fake_pha_incompatible_rmf(idval, clean_astro_ui):
Expand Down

0 comments on commit 578773a

Please sign in to comment.