Skip to content

Commit 8843eb9

Browse files
committed
add a remote regression test
remove unused variable add remote test and restructure fallback catch warning import warnings try changing the warning filter to 'always' check in message, not in str rearrange warning test DEBUG reading the instructions tells you how to use the tool. fix to use pytest.warns
1 parent d26c586 commit 8843eb9

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

astroquery/heasarc/core.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ def _parse_result(self, response, verbose=False):
262262
warnings.warn(NoResultsWarning("No matching rows were found in the query."))
263263
return Table()
264264

265+
if "XTENSION= 'IMAGE '" in response.text:
266+
data = BytesIO(response.content)
267+
return self._blank_table_fallback(data)
268+
265269
try:
266270
data = BytesIO(response.content)
267271
return Table_read(data, hdu=1)
@@ -270,8 +274,6 @@ def _parse_result(self, response, verbose=False):
270274
return self._fallback(response.text)
271275
except Exception:
272276
return self._old_w3query_fallback(response.content)
273-
except AttributeError:
274-
return self._blank_table_fallback(data)
275277

276278

277279
def _args_to_payload(self, **kwargs):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SIMPLE = T / Browse (FitsDisplay V0.2) BITPIX = 8 NAXIS = 0 / Dummy HDU EXTEND = T / Extensions allowed END XTENSION= 'IMAGE ' / Tables not returning data BITPIX = 8 NAXIS = 0 PCOUNT = 0 GCOUNT = 1 COMMENT heasarc_fermilpsc : No matching rows END

astroquery/heasarc/tests/test_heasarc_remote.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import pytest
44
import requests
5+
import warnings
56

67
from ...heasarc import Heasarc
78

89
from .conftest import MockResponse, parametrization_local_save_remote, skycoord_3C_273
910

11+
from astroquery.exceptions import NoResultsWarning
12+
13+
from astropy.coordinates import SkyCoord
14+
from astropy import units as u
15+
1016

1117
@parametrization_local_save_remote
1218
class TestHeasarc:
@@ -96,3 +102,18 @@ def test_query_region(self):
96102
skycoord_3C_273, mission=mission, radius="1 degree")
97103

98104
assert len(table) == 63
105+
106+
def test_query_region_nohits(self):
107+
"""
108+
Regression test for #2560: HEASARC returns a FITS file as a null result
109+
"""
110+
heasarc = Heasarc()
111+
112+
with warnings.catch_warnings(record=True) as warn:
113+
with pytest.warns(NoResultsWarning, match='No matching rows were found in the query.'):
114+
table = heasarc.query_region(
115+
SkyCoord(0.28136*u.deg, -0.09789*u.deg, frame='fk5'),
116+
mission='fermilpsc', radius=0.1*u.deg)
117+
118+
assert len(table) == 0
119+
assert 'heasarc_fermigbrst' in table.meta['COMMENT'][0]

0 commit comments

Comments
 (0)