11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22import numpy as np
33import pytest
4+ import warnings
45
56from astroquery .exceptions import LoginError , NoResultsWarning
67from astroquery .eso import Eso
1516# TODO: make this a configuration item
1617SKIP_SLOW = True
1718
19+ SGRA_SURVEYS = ['195.B-0283' , 'GIRAFFE' , 'HARPS' , 'HAWKI' , 'KMOS' ,
20+ 'MW-BULGE-PSFPHOT' , 'VPHASplus' , 'VVV' , 'VVVX' , 'XSHOOTER' ]
21+
1822
1923@pytest .mark .remote_data
2024class TestEso :
@@ -81,6 +85,7 @@ def test_empty_return(self):
8185 eso = Eso ()
8286 surveys = eso .list_surveys (cache = False )
8387 assert len (surveys ) > 0
88+
8489 # Avoid SESAME
8590 with pytest .warns (NoResultsWarning ):
8691 result_s = eso .query_surveys (surveys [0 ], coord1 = 202.469575 ,
@@ -142,6 +147,8 @@ def test_retrieve_data_and_calib(self):
142147 # list.
143148 assert len (result ) == 1
144149
150+ # TODO: remove filter when https://github.com/astropy/astroquery/issues/2539 is fixed
151+ @pytest .mark .filterwarnings ("ignore::pytest.PytestUnraisableExceptionWarning" )
145152 @pytest .mark .parametrize ('instrument' , instrument_list )
146153 def test_help (self , instrument ):
147154 eso = Eso ()
@@ -166,7 +173,7 @@ def test_each_instrument_SgrAstar(self, tmp_path):
166173 instruments = eso .list_instruments (cache = False )
167174
168175 for instrument in instruments :
169- with pytest . warns ( None ) as record :
176+ with warnings . catch_warnings ( record = True ) as record :
170177 result_i = eso .query_instrument (instrument , coord1 = 266.41681662 ,
171178 coord2 = - 29.00782497 , cache = False )
172179 # Sometimes there are ResourceWarnings, we ignore those for this test
@@ -175,36 +182,30 @@ def test_each_instrument_SgrAstar(self, tmp_path):
175182 else :
176183 assert len (result_i ) > 0
177184
178- @pytest .mark .filterwarnings ("ignore::ResourceWarning" )
179- def test_each_survey_SgrAstar (self , tmp_path ):
185+ def test_each_survey_and_SgrAstar (self , tmp_path ):
180186 eso = Eso ()
181187 eso .cache_location = tmp_path
188+ eso .ROW_LIMIT = 5
189+
182190
183191 surveys = eso .list_surveys (cache = False )
184192 for survey in surveys :
185- with pytest . warns ( None ) as record :
193+ if survey in SGRA_SURVEYS :
186194 result_s = eso .query_surveys (survey , coord1 = 266.41681662 ,
187195 coord2 = - 29.00782497 ,
188196 box = '01 00 00' ,
189197 cache = False )
190- # Sometimes there are ResourceWarnings, we ignore those for this test
191- if len (record ) > 0 and NoResultsWarning in {record [i ].category for i in range (len (record ))}:
198+ assert len (result_s ) > 0
199+ else :
200+ with pytest .warns (NoResultsWarning ):
201+ result_s = eso .query_surveys (survey , coord1 = 266.41681662 ,
202+ coord2 = - 29.00782497 ,
203+ box = '01 00 00' ,
204+ cache = False )
192205 assert result_s is None
193- else :
194- print ([record [i ].message for i in range (len (record ))])
195- assert len (result_s ) > 0
196-
197- @pytest .mark .skipif ("SKIP_SLOW" )
198- @pytest .mark .parametrize ('cache' , (False , True ))
199- def test_each_survey_nosource (self , tmp_path , cache ):
200- eso = Eso ()
201- eso .cache_location = tmp_path
202- eso .ROW_LIMIT = 5
203206
204- surveys = eso .list_surveys (cache = cache )
205- for survey in surveys :
206- # just test that it doesn't crash
207- eso .query_surveys (survey , cache = cache )
207+ generic_result = eso .query_surveys (survey )
208+ assert len (generic_result ) > 0
208209
209210 def test_mixed_case_instrument (self , tmp_path ):
210211 eso = Eso ()
0 commit comments