Skip to content

Commit 206c759

Browse files
committed
MNT: cleanup as PyVO is a required dependency
1 parent 105d232 commit 206c759

File tree

3 files changed

+11
-69
lines changed

3 files changed

+11
-69
lines changed

astroquery/cadc/core.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,11 @@
2121
from astropy.utils.exceptions import AstropyDeprecationWarning
2222
from astropy.utils.decorators import deprecated
2323
from astropy import units as u
24+
import pyvo
25+
from pyvo.auth import authsession
26+
2427
from . import conf
2528

26-
try:
27-
import pyvo
28-
from pyvo.auth import authsession
29-
except ImportError:
30-
print('Please install pyvo. astropy.cadc does not work without it.')
31-
except AstropyDeprecationWarning as e:
32-
if str(e) == 'The astropy.vo.samp module has now been moved to astropy.samp':
33-
# CADC does not use samp and this only affects Python 2.7
34-
print('AstropyDeprecationWarning: {}'.format(str(e)))
35-
else:
36-
raise e
3729

3830
__all__ = ['Cadc', 'CadcClass']
3931

astroquery/cadc/tests/test_cadctap.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,15 @@
1616
from astropy.io.votable import parse
1717
from astroquery.utils.commons import parse_coordinates, FileContainer
1818
from astropy import units as u
19-
from astropy.utils.exceptions import AstropyDeprecationWarning
2019
import pytest
2120
import tempfile
2221
import requests
23-
try:
24-
pyvo_OK = True
25-
from pyvo.auth import authsession, securitymethods
26-
from astroquery.cadc import Cadc, conf
27-
import astroquery.cadc.core as cadc_core
28-
except ImportError:
29-
pyvo_OK = False
30-
pytest.skip("Install pyvo for the cadc module.", allow_module_level=True)
31-
except AstropyDeprecationWarning as ex:
32-
if str(ex) == \
33-
'The astropy.vo.samp module has now been moved to astropy.samp':
34-
print('AstropyDeprecationWarning: {}'.format(str(ex)))
35-
else:
36-
raise ex
37-
try:
38-
from unittest.mock import Mock, patch, PropertyMock
39-
except ImportError:
40-
pytest.skip("Install mock for the cadc tests.", allow_module_level=True)
22+
23+
from pyvo.auth import securitymethods
24+
from astroquery.cadc import Cadc, conf
25+
import astroquery.cadc.core as cadc_core
26+
27+
from unittest.mock import Mock, patch, PropertyMock
4128

4229

4330
def data_path(filename):
@@ -47,7 +34,6 @@ def data_path(filename):
4734

4835
@patch('astroquery.cadc.core.get_access_url',
4936
Mock(side_effect=lambda x: 'https://some.url'))
50-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
5137
def test_get_tables():
5238
# default parameters
5339
table_set = PropertyMock()
@@ -62,7 +48,6 @@ def test_get_tables():
6248

6349
@patch('astroquery.cadc.core.get_access_url',
6450
Mock(side_effect=lambda x: 'https://some.url'))
65-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
6651
def test_get_table():
6752
table_set = PropertyMock()
6853
tables_result = [Mock() for _ in range(3)]
@@ -80,7 +65,6 @@ def test_get_table():
8065

8166
@patch('astroquery.cadc.core.get_access_url',
8267
Mock(side_effect=lambda x: 'https://some.url'))
83-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
8468
def test_get_collections():
8569
cadc = Cadc()
8670

@@ -106,7 +90,6 @@ def mock_run_query(query, output_format=None, maxrec=None,
10690

10791
@patch('astroquery.cadc.core.get_access_url',
10892
Mock(side_effect=lambda x: 'https://some.url'))
109-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
11093
def test_load_async_job():
11194
with patch('astroquery.cadc.core.pyvo.dal.TAPService', autospec=True) as tapservice_mock:
11295
with patch('astroquery.cadc.core.pyvo.dal.AsyncTAPJob',
@@ -124,7 +107,6 @@ def test_load_async_job():
124107
@pytest.mark.skip('Disabled until job listing available in pyvo')
125108
@patch('astroquery.cadc.core.get_access_url',
126109
Mock(side_effect=lambda x: 'https://some.url'))
127-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
128110
def test_list_async_jobs():
129111
with patch('astroquery.cadc.core.pyvo.dal.TAPService', autospec=True) as tapservice_mock:
130112
tapservice_mock.return_value.baseurl.return_value = 'https://www.example.com/tap'
@@ -136,7 +118,6 @@ def test_list_async_jobs():
136118
Mock(side_effect=lambda x, y=None: 'https://some.url'))
137119
@patch('astroquery.cadc.core.pyvo.dal.TAPService.capabilities', []) # TAP capabilities not needed
138120
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService.capabilities', []) # DL capabilities not needed
139-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
140121
def test_auth():
141122
# the Cadc() will cause a remote data call to TAP service capabilities
142123
# To avoid this, use an anonymous session and replace it with an
@@ -183,7 +164,6 @@ def test_auth():
183164

184165
# make sure that caps is reset at the end of the test
185166
@patch('astroquery.cadc.core.get_access_url.caps', {})
186-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
187167
def test_get_access_url():
188168
# testing implementation of requests.get method:
189169
def get(url, **kwargs):
@@ -219,7 +199,6 @@ def raise_for_status(self):
219199
Mock(side_effect=lambda x, y=None: 'https://some.url'))
220200
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService',
221201
Mock(return_value=Mock(capabilities=[]))) # DL capabilities not needed
222-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
223202
def test_get_data_urls():
224203

225204
def get(*args, **kwargs):
@@ -268,7 +247,6 @@ class Result:
268247

269248
@patch('astroquery.cadc.core.get_access_url',
270249
Mock(side_effect=lambda x, y=None: 'https://some.url'))
271-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
272250
def test_misc():
273251
cadc = Cadc()
274252

@@ -302,7 +280,6 @@ def test_misc():
302280
Mock(return_value=Mock(capabilities=[]))) # TAP capabilities not needed
303281
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService',
304282
Mock(return_value=Mock(capabilities=[]))) # DL capabilities not needed
305-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
306283
def test_get_image_list():
307284
def get(*args, **kwargs):
308285
class CapsResponse:
@@ -370,7 +347,6 @@ def __init__(self, **param_dict):
370347

371348
@patch('astroquery.cadc.core.get_access_url',
372349
Mock(side_effect=lambda x, y=None: 'https://some.url'))
373-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
374350
def test_exec_sync():
375351
# save results in a file
376352
# create the VOTable result
@@ -411,7 +387,6 @@ def test_exec_sync():
411387
@patch('astroquery.cadc.core.CadcClass.exec_sync', Mock())
412388
@patch('astroquery.cadc.core.CadcClass.get_image_list',
413389
Mock(side_effect=lambda x, y, z: ['https://some.url']))
414-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
415390
def test_get_images():
416391
with patch('astroquery.utils.commons.get_readable_fileobj', autospec=True) as readable_fobj_mock:
417392
readable_fobj_mock.return_value = open(data_path('query_images.fits'), 'rb')
@@ -429,7 +404,6 @@ def test_get_images():
429404
@patch('astroquery.cadc.core.CadcClass.exec_sync', Mock())
430405
@patch('astroquery.cadc.core.CadcClass.get_image_list',
431406
Mock(side_effect=lambda x, y, z: ['https://some.url']))
432-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
433407
def test_get_images_async():
434408
with patch('astroquery.utils.commons.get_readable_fileobj', autospec=True) as readable_fobj_mock:
435409
readable_fobj_mock.return_value = open(data_path('query_images.fits'), 'rb')

astroquery/cadc/tests/test_cadctap_remote.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,10 @@
1414
from astropy import units as u
1515

1616
from astroquery.cadc import Cadc
17-
from astropy.utils.exceptions import AstropyDeprecationWarning
1817
from astroquery.utils.commons import parse_coordinates, FileContainer
1918

20-
try:
21-
pyvo_OK = True
22-
import pyvo # noqa
23-
from pyvo.auth import authsession
24-
except ImportError:
25-
pyvo_OK = False
26-
except AstropyDeprecationWarning as e:
27-
if str(e) == 'The astropy.vo.samp module has now been moved to astropy.samp':
28-
print('AstropyDeprecationWarning: {}'.format(str(e)))
29-
else:
30-
raise e
19+
from pyvo.auth import authsession
20+
3121

3222
# to run just one test during development, set this variable to True
3323
# and comment out the skipif of the single test to run.
@@ -41,7 +31,6 @@
4131
class TestCadcClass:
4232
# now write tests for each method here
4333
@pytest.mark.skipif(one_test, reason='One test mode')
44-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
4534
def test_get_collections(self):
4635
cadc = Cadc()
4736
result = cadc.get_collections()
@@ -62,7 +51,6 @@ def test_get_collections(self):
6251
assert 'Optical' in result['DAO']['Bands']
6352

6453
@pytest.mark.skipif(one_test, reason='One test mode')
65-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
6654
def test_query_region(self):
6755
cadc = Cadc()
6856
result = cadc.query_region('08h45m07.5s +54d18m00s', collection='CFHT')
@@ -89,7 +77,6 @@ def test_query_region(self):
8977
assert len(results) > 20
9078

9179
@pytest.mark.skipif(one_test, reason='One test mode')
92-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
9380
def test_query_name(self):
9481
cadc = Cadc()
9582
result1 = cadc.query_name('M31-B14')
@@ -99,7 +86,6 @@ def test_query_name(self):
9986
assert len(result1) == len(result2)
10087

10188
@pytest.mark.skipif(one_test, reason='One test mode')
102-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
10389
def test_query(self):
10490
cadc = Cadc()
10591
result = cadc.exec_sync(
@@ -116,7 +102,6 @@ def test_query(self):
116102
@pytest.mark.skipif(one_test, reason='One test mode')
117103
@pytest.mark.skip('Disabled for now until pyvo starts supporting '
118104
'different output formats')
119-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
120105
def test_query_format(self):
121106
cadc = Cadc()
122107
query = "select top 1 observationID, collection from caom2.Observation"
@@ -128,7 +113,6 @@ def test_query_format(self):
128113
or 'CADC_PASSWD' not in os.environ),
129114
reason='Requires real CADC user/password (CADC_USER '
130115
'and CADC_PASSWD environment variables)')
131-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
132116
def test_login_with_user_password(self):
133117
for auth_session in [None, authsession.AuthSession(),
134118
requests.Session()]:
@@ -162,7 +146,6 @@ def test_login_with_user_password(self):
162146
@pytest.mark.skipif('CADC_CERT' not in os.environ,
163147
reason='Requires real CADC certificate (CADC_CERT '
164148
'environment variable)')
165-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
166149
def test_login_with_cert(self):
167150
for auth_session in [requests.Session()]:
168151
cadc = Cadc(auth_session=auth_session)
@@ -191,7 +174,6 @@ def test_login_with_cert(self):
191174
@pytest.mark.skipif('CADC_CERT' not in os.environ,
192175
reason='Requires real CADC certificate (CADC_CERT '
193176
'environment variable)')
194-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
195177
def test_authsession(self):
196178
# repeat previous test
197179
auth_session = requests.Session()
@@ -211,7 +193,6 @@ def test_authsession(self):
211193
assert len(result) == 0
212194

213195
@pytest.mark.skipif(one_test, reason='One test mode')
214-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
215196
@pytest.mark.xfail(reason='#2325')
216197
def test_get_images(self):
217198
cadc = Cadc()
@@ -224,7 +205,6 @@ def test_get_images(self):
224205
assert isinstance(image, fits.HDUList)
225206

226207
@pytest.mark.skipif(one_test, reason='One test mode')
227-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
228208
@pytest.mark.skipif(skip_slow, reason='Avoid timeout errors')
229209
def test_get_images_against_AS(self):
230210
cadc = Cadc()
@@ -259,7 +239,6 @@ def test_get_images_against_AS(self):
259239
assert len(filtered_resp_urls) == len(image_urls)
260240

261241
@pytest.mark.skipif(one_test, reason='One test mode')
262-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
263242
@pytest.mark.xfail(reason='#2325')
264243
def test_get_images_async(self):
265244
cadc = Cadc()
@@ -271,7 +250,6 @@ def test_get_images_async(self):
271250
assert isinstance(obj, FileContainer)
272251

273252
@pytest.mark.skipif(one_test, reason='One test mode')
274-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
275253
def test_async(self):
276254
# test async calls
277255
cadc = Cadc()
@@ -300,7 +278,6 @@ def test_async(self):
300278
# job.delete() # BUG in CADC
301279

302280
@pytest.mark.skipif(one_test, reason='One test mode')
303-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
304281
def test_list_tables(self):
305282
cadc = Cadc()
306283
table_names = cadc.get_tables(only_names=True)
@@ -320,7 +297,6 @@ def test_list_tables(self):
320297
@pytest.mark.skipif('CADC_CERT' not in os.environ,
321298
reason='Requires real CADC certificate (CADC_CERT '
322299
'environment variable)')
323-
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
324300
@pytest.mark.xfail(reason='#2325')
325301
def test_list_jobs(self):
326302
cadc = Cadc()

0 commit comments

Comments
 (0)