Skip to content

Commit fdbad11

Browse files
author
David Turner
committed
Added try-excepts to all product retrieval tests to catch NoProductAvailableErrors and instead record them as test failures.
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent 4504f19 commit fdbad11

9 files changed

Lines changed: 156 additions & 72 deletions

File tree

tests/test_generate/test_ciao_phot.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 4/27/26, 5:17 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 7:14 PM. Copyright (c) The Contributors.
33

44
import unittest
55

66
from astropy.units import Quantity
77

8-
from xga.exceptions import TelescopeNotAssociatedError
8+
from xga.exceptions import TelescopeNotAssociatedError, NoProductAvailableError
99
from xga.generate.ciao.phot import chandra_image_expmap
1010
from xga.products import Image
1111
from .. import get_test_source
@@ -41,20 +41,20 @@ def test_chandra_image_expmap_if_available(self):
4141
try:
4242
im = self.src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'),
4343
telescope='chandra')
44-
if isinstance(im, list):
45-
for i in im:
46-
assert i.telescope == 'chandra'
47-
assert i.energy_bounds[0] == Quantity(0.5, 'keV')
48-
assert i.energy_bounds[1] == Quantity(2.0, 'keV')
49-
assert isinstance(i, Image)
50-
else:
51-
assert im.telescope == 'chandra'
52-
assert im.energy_bounds[0] == Quantity(0.5, 'keV')
53-
assert im.energy_bounds[1] == Quantity(2.0, 'keV')
54-
assert isinstance(im, Image)
55-
except Exception:
56-
# If retrieval fails, that's OK for now - at least generation didn't crash
57-
pass
44+
except NoProductAvailableError:
45+
self.fail("NoProductAvailableError raised when retrieving Chandra images.")
46+
47+
if isinstance(im, list):
48+
for i in im:
49+
assert i.telescope == 'chandra'
50+
assert i.energy_bounds[0] == Quantity(0.5, 'keV')
51+
assert i.energy_bounds[1] == Quantity(2.0, 'keV')
52+
assert isinstance(i, Image)
53+
else:
54+
assert im.telescope == 'chandra'
55+
assert im.energy_bounds[0] == Quantity(0.5, 'keV')
56+
assert im.energy_bounds[1] == Quantity(2.0, 'keV')
57+
assert isinstance(im, Image)
5858

5959

6060
if __name__ == "__main__":

tests/test_generate/test_ciao_spec.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 4/27/26, 5:17 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 7:14 PM. Copyright (c) The Contributors.
33

44
import unittest
55

6-
from xga.exceptions import TelescopeNotAssociatedError
6+
from xga.exceptions import TelescopeNotAssociatedError, NoProductAvailableError
77
from xga.generate.ciao.spec import specextract_spectrum
88
from xga.products import Spectrum
99
from .. import get_test_source
@@ -38,16 +38,16 @@ def test_specextract_spectrum_if_available(self):
3838
# Try to retrieve the generated products
3939
try:
4040
spec = self.src.get_spectra('r500', telescope='chandra')
41-
if isinstance(spec, list):
42-
for s in spec:
43-
assert s.telescope == 'chandra'
44-
assert isinstance(s, Spectrum)
45-
else:
46-
assert spec.telescope == 'chandra'
47-
assert isinstance(spec, Spectrum)
48-
except Exception:
49-
# If retrieval fails, that's OK for now - at least generation didn't crash
50-
pass
41+
except NoProductAvailableError:
42+
self.fail("NoProductAvailableError raised when retrieving Chandra spectra.")
43+
44+
if isinstance(spec, list):
45+
for s in spec:
46+
assert s.telescope == 'chandra'
47+
assert isinstance(s, Spectrum)
48+
else:
49+
assert spec.telescope == 'chandra'
50+
assert isinstance(spec, Spectrum)
5151

5252

5353
if __name__ == "__main__":

tests/test_generate/test_esass_phot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 6:19 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 6:49 PM. Copyright (c) The Contributors.
33

44
import unittest
55

@@ -102,8 +102,11 @@ def test_expmap(self):
102102
def test_expmap_combined_obs(self):
103103
expmap(self.src, Quantity(0.5, 'keV'), Quantity(3, 'keV'), combine_obs=True)
104104

105-
exp = self.src.get_combined_expmaps(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(3, 'keV'),
106-
telescope='erass')
105+
try:
106+
exp = self.src.get_combined_expmaps(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(3, 'keV'),
107+
telescope='erass')
108+
except NoProductAvailableError:
109+
self.fail("NoProductAvailableError raised.")
107110

108111
assert exp.telescope == 'erass'
109112
assert exp.energy_bounds[0] == Quantity(0.5, 'keV')

tests/test_generate/test_sas_phot.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 11:56 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 7:14 PM. Copyright (c) The Contributors.
33

44
import unittest
55

66
from astropy.units import Quantity
77

8-
from xga.exceptions import TelescopeNotAssociatedError
8+
from xga.exceptions import TelescopeNotAssociatedError, NoProductAvailableError
99
from xga.generate.sas.phot import evselect_image, eexpmap, emosaic
1010
from xga.products import Image, ExpMap
1111
from .. import get_test_source
@@ -34,8 +34,12 @@ def test_evselect_image_no_tel_error(self):
3434
def test_evselect_image(self):
3535
evselect_image(self.src, Quantity(0.4, 'keV'), Quantity(3, 'keV'))
3636

37-
im = self.src.get_images(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
38-
telescope='xmm')
37+
try:
38+
im = self.src.get_images(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
39+
telescope='xmm')
40+
except NoProductAvailableError:
41+
self.fail("NoProductAvailableError raised.")
42+
3943
if isinstance(im, list):
4044
for i in im:
4145
assert i.telescope == 'xmm'
@@ -52,8 +56,12 @@ def test_evselect_image(self):
5256
def test_eexpmap(self):
5357
eexpmap(self.src, Quantity(0.4, 'keV'), Quantity(3, 'keV'))
5458

55-
exp = self.src.get_expmaps(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
56-
telescope='xmm')
59+
try:
60+
exp = self.src.get_expmaps(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
61+
telescope='xmm')
62+
except NoProductAvailableError:
63+
self.fail("NoProductAvailableError raised.")
64+
5765
if isinstance(exp, list):
5866
for e in exp:
5967
assert e.telescope == 'xmm'
@@ -70,13 +78,17 @@ def test_eexpmap(self):
7078
def test_emosaic_incorrect_input(self):
7179
with self.assertRaises(ValueError):
7280
emosaic(self.src, 'wrong')
73-
81+
7482
@require_sas
7583
def test_emosaic_image(self):
7684
emosaic(self.src, 'image', lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'))
77-
78-
im = self.src.get_combined_images(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
79-
telescope='xmm')
85+
86+
try:
87+
im = self.src.get_combined_images(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
88+
telescope='xmm')
89+
except NoProductAvailableError:
90+
self.fail("NoProductAvailableError raised.")
91+
8092
if isinstance(im, list):
8193
for i in im:
8294
assert i.telescope == 'xmm'
@@ -93,9 +105,13 @@ def test_emosaic_image(self):
93105
@require_sas
94106
def test_emosaic_expmap(self):
95107
emosaic(self.src, 'expmap', lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'))
96-
97-
exp = self.src.get_combined_expmaps(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
98-
telescope='xmm')
108+
109+
try:
110+
exp = self.src.get_combined_expmaps(lo_en=Quantity(0.4, 'keV'), hi_en=Quantity(3, 'keV'),
111+
telescope='xmm')
112+
except NoProductAvailableError:
113+
self.fail("NoProductAvailableError raised.")
114+
99115
if isinstance(exp, list):
100116
for e in exp:
101117
assert e.telescope == 'xmm'

tests/test_generate/test_sas_spec.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 4/27/26, 5:17 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 7:14 PM. Copyright (c) The Contributors.
33

44
import unittest
55

66
from astropy.units import Quantity
77

8+
from xga.exceptions import NoProductAvailableError
89
from xga.generate.sas.lightcurve import evselect_lightcurve
910
from xga.generate.sas.spec import evselect_spectrum, spectrum_set
1011
from xga.products import Spectrum, LightCurve, AnnularSpectra
@@ -21,7 +22,10 @@ def setUpClass(cls):
2122
def test_evselect_spectrum(self):
2223
evselect_spectrum(self.src, 'r500')
2324

24-
spec = self.src.get_spectra('r500', telescope='xmm')
25+
try:
26+
spec = self.src.get_spectra('r500', telescope='xmm')
27+
except NoProductAvailableError:
28+
self.fail("NoProductAvailableError raised.")
2529

2630
if isinstance(spec, list):
2731
for sp in spec:
@@ -39,7 +43,11 @@ def test_spectrum_set(self):
3943
radii = Quantity([0, 100, 200, 500], 'kpc')
4044
spectrum_set(self.src, radii)
4145

42-
ann_spec = self.src.get_annular_spectra(radii, telescope='xmm')
46+
try:
47+
ann_spec = self.src.get_annular_spectra(radii, telescope='xmm')
48+
except NoProductAvailableError:
49+
self.fail("NoProductAvailableError raised.")
50+
4351
assert isinstance(ann_spec, AnnularSpectra)
4452
assert ann_spec.telescope == 'xmm'
4553
assert len(ann_spec) == 3
@@ -51,7 +59,10 @@ def test_evselect_lightcurve(self):
5159
"""
5260
evselect_lightcurve(self.src, 'r500')
5361

54-
lc = self.src.get_lightcurves('r500', telescope='xmm')
62+
try:
63+
lc = self.src.get_lightcurves('r500', telescope='xmm')
64+
except NoProductAvailableError:
65+
self.fail("NoProductAvailableError raised.")
5566

5667
if isinstance(lc, list):
5768
for l in lc:

tests/test_sources/test_combined_products.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 11:57 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 6:52 PM. Copyright (c) The Contributors.
33

44
import unittest
55

@@ -45,8 +45,12 @@ def test_erass_multiobs_combined_inst_param(self):
4545
pass # May not exist if TM1 not available
4646

4747
# Retrieve multi-obs + combined inst
48-
spec_comb = self.src.get_spectra(Quantity(500, 'kpc'), obs_id='combined', inst='combined',
49-
group_spec=True, min_counts=5, telescope='erass')
48+
try:
49+
spec_comb = self.src.get_spectra(Quantity(500, 'kpc'), obs_id='combined', inst='combined',
50+
group_spec=True, min_counts=5, telescope='erass')
51+
except NoProductAvailableError:
52+
self.fail("NoProductAvailableError raised when retrieving multi-obs combined eRASS spectrum.")
53+
5054
assert spec_comb.obs_id == 'combined'
5155
assert spec_comb.instrument == 'combined'
5256

@@ -68,16 +72,20 @@ def test_get_combined_spectra_wrapper_equivalence(self):
6872
try:
6973
spec_direct = self.src.get_spectra(Quantity(500, 'kpc'), obs_id='combined', inst='combined',
7074
group_spec=True, min_counts=5, telescope='erass')
75+
except NoProductAvailableError:
76+
self.fail("NoProductAvailableError raised by get_spectra(obs_id='combined')")
77+
78+
try:
7179
spec_wrapper = self.src.get_combined_spectra(Quantity(500, 'kpc'), inst='combined',
7280
group_spec=True, min_counts=5, telescope='erass')
73-
74-
# Should be the same product
75-
if not isinstance(spec_direct, list):
76-
assert spec_direct.path == spec_wrapper.path
77-
else:
78-
assert len(spec_direct) == len(spec_wrapper)
7981
except NoProductAvailableError:
80-
self.skipTest("Combined spectra not available")
82+
self.fail("NoProductAvailableError raised by get_combined_spectra()")
83+
84+
# Should be the same product
85+
if not isinstance(spec_direct, list):
86+
assert spec_direct.path == spec_wrapper.path
87+
else:
88+
assert len(spec_direct) == len(spec_wrapper)
8189

8290

8391
if __name__ == "__main__":

tests/test_sources/test_loading.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 11:36 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/10/26, 7:14 PM. Copyright (c) The Contributors.
33

44
import unittest
55

66
from astropy.units import Quantity
77

8+
from xga.exceptions import NoProductAvailableError
89
from xga.generate.ciao.phot import chandra_image_expmap
910
from xga.generate.ciao.spec import specextract_spectrum
1011
from xga.generate.sas.phot import evselect_image, eexpmap
@@ -36,7 +37,11 @@ def test_xmm_image_loading(self):
3637
search_distance={'xmm': Quantity(30, 'arcmin')}, load_profiles=False)
3738

3839
# Retrieve and verify
39-
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='xmm')
40+
try:
41+
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='xmm')
42+
except NoProductAvailableError:
43+
self.fail("NoProductAvailableError raised.")
44+
4045
if not isinstance(imgs, list):
4146
imgs = [imgs]
4247

@@ -60,7 +65,11 @@ def test_xmm_expmap_loading(self):
6065
search_distance={'xmm': Quantity(30, 'arcmin')}, load_profiles=False)
6166

6267
# Retrieve and verify
63-
exps = src.get_expmaps(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='xmm')
68+
try:
69+
exps = src.get_expmaps(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='xmm')
70+
except NoProductAvailableError:
71+
self.fail("NoProductAvailableError raised.")
72+
6473
if not isinstance(exps, list):
6574
exps = [exps]
6675

@@ -83,7 +92,11 @@ def test_xmm_spectrum_loading(self):
8392
search_distance={'xmm': Quantity(30, 'arcmin')}, load_profiles=False)
8493

8594
# Retrieve and verify
86-
specs = src.get_spectra('r500', telescope='xmm')
95+
try:
96+
specs = src.get_spectra('r500', telescope='xmm')
97+
except NoProductAvailableError:
98+
self.fail("NoProductAvailableError raised.")
99+
87100
if not isinstance(specs, list):
88101
specs = [specs]
89102

@@ -107,7 +120,11 @@ def test_erass_image_loading(self):
107120
search_distance={'erass': Quantity(3.6, 'deg')}, load_profiles=False)
108121

109122
# Retrieve and verify
110-
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='erass')
123+
try:
124+
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='erass')
125+
except NoProductAvailableError:
126+
self.fail("NoProductAvailableError raised.")
127+
111128
if not isinstance(imgs, list):
112129
imgs = [imgs]
113130

@@ -132,7 +149,11 @@ def test_erass_spectrum_loading(self):
132149
search_distance={'erass': Quantity(3.6, 'deg')}, load_profiles=False)
133150

134151
# Retrieve and verify
135-
specs = src.get_spectra('r500', telescope='erass')
152+
try:
153+
specs = src.get_spectra('r500', telescope='erass')
154+
except NoProductAvailableError:
155+
self.fail("NoProductAvailableError raised.")
156+
136157
if not isinstance(specs, list):
137158
specs = [specs]
138159

@@ -156,7 +177,11 @@ def test_chandra_image_loading(self):
156177
search_distance={'chandra': Quantity(10, 'arcmin')}, load_profiles=False)
157178

158179
# Retrieve and verify
159-
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='chandra')
180+
try:
181+
imgs = src.get_images(lo_en=Quantity(0.5, 'keV'), hi_en=Quantity(2.0, 'keV'), telescope='chandra')
182+
except NoProductAvailableError:
183+
self.fail("NoProductAvailableError raised.")
184+
160185
if not isinstance(imgs, list):
161186
imgs = [imgs]
162187

@@ -180,7 +205,11 @@ def test_chandra_spectrum_loading(self):
180205
search_distance={'chandra': Quantity(10, 'arcmin')}, load_profiles=False)
181206

182207
# Retrieve and verify
183-
specs = src.get_spectra('r500', telescope='chandra')
208+
try:
209+
specs = src.get_spectra('r500', telescope='chandra')
210+
except NoProductAvailableError:
211+
self.fail("NoProductAvailableError raised.")
212+
184213
if not isinstance(specs, list):
185214
specs = [specs]
186215

0 commit comments

Comments
 (0)