Skip to content

Commit 3cba46f

Browse files
committed
MAINT: fixing warning handling for remaining non-remote tests, and some remote cases
1 parent 50ea662 commit 3cba46f

File tree

7 files changed

+53
-30
lines changed

7 files changed

+53
-30
lines changed

astroquery/cadc/tests/test_cadctap.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
from io import BytesIO
99
from urllib.parse import urlsplit, parse_qs
10+
from pathlib import Path
1011
import os
1112
import sys
1213

@@ -177,9 +178,7 @@ def raise_for_status(self):
177178
class CapabilitiesResponse:
178179
def __init__(self):
179180
caps_file = data_path('tap_caps.xml')
180-
with open(caps_file, 'r') as infile:
181-
text = infile.read()
182-
self.text = text
181+
self.text = Path(caps_file).read_text()
183182

184183
def raise_for_status(self):
185184
pass
@@ -408,7 +407,7 @@ def test_get_images():
408407
Mock(side_effect=lambda x, y, z: ['https://some.url']))
409408
def test_get_images_async():
410409
with patch('astroquery.utils.commons.get_readable_fileobj', autospec=True) as readable_fobj_mock:
411-
readable_fobj_mock.return_value = open(data_path('query_images.fits'), 'rb')
410+
readable_fobj_mock.return_value = Path(data_path('query_images.fits'))
412411

413412
cadc = Cadc()
414413
readable_objs = cadc.get_images_async('08h45m07.5s +54d18m00s',

astroquery/cadc/tests/test_cadctap_remote.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99
import os
1010
import requests
11+
from pathlib import Path
1112
from datetime import datetime
1213
from astropy.coordinates import SkyCoord
1314
from astropy.io import fits
@@ -180,7 +181,6 @@ def test_authsession(self):
180181
result = cadc.exec_sync(query)
181182
assert len(result) == 0
182183

183-
@pytest.mark.xfail(reason='#2325')
184184
def test_get_images(self):
185185
cadc = Cadc()
186186
coords = '08h45m07.5s +54d18m00s'
@@ -224,7 +224,6 @@ def test_get_images_against_AS(self):
224224

225225
assert len(filtered_resp_urls) == len(image_urls)
226226

227-
@pytest.mark.xfail(reason='#2325')
228227
def test_get_images_async(self):
229228
cadc = Cadc()
230229
coords = '01h45m07.5s +23d18m00s'
@@ -294,3 +293,20 @@ def test_list_jobs(self):
294293
if len(jobs) > 5:
295294
jobs_subset = cadc.list_async_jobs(last=5)
296295
assert len(jobs_subset) == 5
296+
297+
@pytest.mark.xfail(reason='https://github.com/astropy/astroquery/issues/2538')
298+
def test_uploads(self, tmp_path):
299+
cadc = Cadc()
300+
# save a few observations on a local file
301+
output_file = Path(tmp_path, 'my_observations.xml')
302+
cadc.exec_sync("SELECT TOP 3 observationID FROM caom2.Observation",
303+
output_file=output_file)#'my_observations.xml')
304+
# assert output_file.exists()
305+
306+
# now use them to join with the remote table
307+
results = cadc.exec_sync(
308+
"SELECT o.observationID, intent FROM caom2.Observation o JOIN "
309+
"tap_upload.test_upload tu ON o.observationID=tu.observationID",
310+
uploads={'test_upload': output_file})#'my_observations.xml'})
311+
312+
assert len(results) == 3

astroquery/eso/tests/test_eso_remote.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import numpy as np
33
import pytest
4+
import warnings
45

56
from astroquery.exceptions import LoginError, NoResultsWarning
67
from astroquery.eso import Eso
@@ -15,6 +16,9 @@
1516
# TODO: make this a configuration item
1617
SKIP_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
2024
class 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()

astroquery/ipac/irsa/tests/test_irsa_remote.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ def test_query_region_async_polygon(self):
4949

5050
def test_query_region_polygon(self):
5151
polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)]
52-
result = Irsa.query_region(
53-
"m31", catalog="fp_psc", spatial="Polygon", polygon=polygon, cache=False)
52+
with pytest.warns(UserWarning, match='Polygon endpoints are being interpreted'):
53+
result = Irsa.query_region("m31", catalog="fp_psc", spatial="Polygon",
54+
polygon=polygon, cache=False)
5455

5556
assert isinstance(result, Table)
5657

docs/cadc/cadc.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ Multiple temporary tables to be used at once can be specified as such.
444444

445445
More details about temporary table upload can be found in the IVOA TAP specification.
446446

447+
.. TODO: remove the IGNORE_WARNINGS once https://github.com/astropy/astroquery/issues/2538 is fixed
447448
.. doctest-remote-data::
448449

449450
>>> from astroquery.cadc import Cadc
@@ -460,14 +461,15 @@ More details about temporary table upload can be found in the IVOA TAP specifica
460461
>>> # now use them to join with the remote table
461462
>>> results = cadc.exec_sync("SELECT o.observationID, intent FROM caom2.Observation o "
462463
... "JOIN tap_upload.test_upload tu ON o.observationID=tu.observationID",
463-
... uploads={'test_upload': 'my_observations.xml'})
464+
... uploads={'test_upload': 'my_observations.xml'}) # doctest: +IGNORE_WARNINGS
464465
>>> print(results) # doctest: +IGNORE_OUTPUT
465466
observationID intent
466467
---------------------------------- -------
467468
c13a_060826_044314_ori science
468469
tess2021167190903-s0039-1-3-0210-s science
469470
tu1657207 science
470471

472+
471473
The feature allows a user to save the results of a query to use them later or
472474
correlate them with data in other TAP services.
473475

docs/ipac/irsa/irsa.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ is an ra, dec pair expressed in degrees:
175175

176176
>>> from astroquery.ipac.irsa import Irsa
177177
>>> table = Irsa.query_region("m31", catalog="fp_psc", spatial="Polygon",
178-
... polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)])
178+
... polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)]) # doctest: +IGNORE_WARNINGS
179179
>>> print(table)
180180
ra dec clon clat ... ext_key j_h h_k j_k
181181
deg deg ...

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ filterwarnings =
4747
# utils.commons.parse_coordinates, we should remove its usage:
4848
ignore:Coordinate string is being interpreted as an ICRS coordinate:astroquery.exceptions.InputWarning
4949
ignore:Coordinate string is being interpreted as an ICRS coordinate:UserWarning
50+
# To be removed with a fix for https://github.com/astropy/astroquery/issues/2523
51+
ignore::bs4.builder.XMLParsedAsHTMLWarning
52+
# To be removed with a fix for https://github.com/astropy/astroquery/issues/2242
53+
ignore::astropy.io.votable.exceptions.E02
5054
# Warnings from yet to be refactored or to be removed modules
5155
ignore:Experimental. ALFALFA:UserWarning
5256
ignore:Experimental. Fermi-LAT:UserWarning

0 commit comments

Comments
 (0)