Skip to content

Commit 9270204

Browse files
committed
Fixing ESO test by catching expected NoResultsWarnings
1 parent 5b9a86e commit 9270204

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

astroquery/eso/tests/test_eso_remote.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import pytest
44
import tempfile
55
import shutil
6-
from ...exceptions import LoginError
6+
import warnings
7+
8+
from astroquery.exceptions import LoginError, NoResultsWarning
79

810
from ...eso import Eso
911

@@ -93,8 +95,9 @@ def test_empty_return(self):
9395
surveys = eso.list_surveys(cache=False)
9496
assert len(surveys) > 0
9597
# Avoid SESAME
96-
result_s = eso.query_surveys(surveys[0], coord1=202.469575,
97-
coord2=47.195258, cache=False)
98+
with pytest.warns(NoResultsWarning):
99+
result_s = eso.query_surveys(surveys[0], coord1=202.469575,
100+
coord2=47.195258, cache=False)
98101

99102
assert result_s is None
100103

@@ -163,7 +166,7 @@ def test_apex_retrieval(self):
163166
tbl = eso.query_apex_quicklooks(prog_id='095.F-9802')
164167
tblb = eso.query_apex_quicklooks('095.F-9802')
165168

166-
assert len(tbl) == 4
169+
assert len(tbl) == 5
167170
assert set(tbl['Release Date']) == {'2015-07-17', '2015-07-18',
168171
'2015-09-15', '2015-09-18'}
169172

@@ -174,20 +177,35 @@ def test_each_instrument_SgrAstar(self, temp_dir):
174177
eso.cache_location = temp_dir
175178

176179
instruments = eso.list_instruments(cache=False)
177-
for instrument in instruments:
178-
result_i = eso.query_instrument(instrument, coord1=266.41681662,
179-
coord2=-29.00782497, cache=False)
180180

181+
for instrument in instruments:
182+
with pytest.warns(None) as record:
183+
result_i = eso.query_instrument(instrument, coord1=266.41681662,
184+
coord2=-29.00782497, cache=False)
185+
# Sometimes there are ResourceWarnings, we ignore those for this test
186+
if len(record) > 0 and NoResultsWarning in {record[i].category for i in range(len(record))}:
187+
assert result_i is None
188+
else:
189+
assert len(result_i) > 0
190+
191+
@pytest.mark.filterwarnings("ignore::ResourceWarning")
181192
def test_each_survey_SgrAstar(self, temp_dir):
182193
eso = Eso()
183194
eso.cache_location = temp_dir
184195

185196
surveys = eso.list_surveys(cache=False)
186197
for survey in surveys:
187-
result_s = eso.query_surveys(survey, coord1=266.41681662,
188-
coord2=-29.00782497,
189-
box='01 00 00',
190-
cache=False)
198+
with pytest.warns(None) as record:
199+
result_s = eso.query_surveys(survey, coord1=266.41681662,
200+
coord2=-29.00782497,
201+
box='01 00 00',
202+
cache=False)
203+
# Sometimes there are ResourceWarnings, we ignore those for this test
204+
if len(record) > 0 and NoResultsWarning in {record[i].category for i in range(len(record))}:
205+
assert result_s is None
206+
else:
207+
print([record[i].message for i in range(len(record))])
208+
assert len(result_s) > 0
191209

192210
@pytest.mark.skipif("SKIP_SLOW")
193211
@pytest.mark.parametrize('cache', (False, True))

0 commit comments

Comments
 (0)