Skip to content

Commit 96f63eb

Browse files
authored
Merge pull request #2389 from bsipocz/pyvo_usage_cleanup
MNT: cleanup deprecations and obsolte checks
2 parents 7231ca1 + 3aa91b4 commit 96f63eb

File tree

5 files changed

+23
-182
lines changed

5 files changed

+23
-182
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ hsa
1313
Service fixes and enhancements
1414
------------------------------
1515

16+
cadc
17+
^^^^
18+
19+
- Deprecated keywords and ``run_query`` method have been removed. [#2389]
20+
1621
casda
1722
^^^^^
1823

astroquery/cadc/core.py

Lines changed: 9 additions & 82 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

@@ -78,17 +70,14 @@ class CadcClass(BaseQuery):
7870
CADCLOGIN_SERVICE_URI = conf.CADCLOGIN_SERVICE_URI
7971
TIMEOUT = conf.TIMEOUT
8072

81-
def __init__(self, url=None, tap_plus_handler=None, verbose=None,
82-
auth_session=None):
73+
def __init__(self, url=None, auth_session=None):
8374
"""
8475
Initialize Cadc object
8576
8677
Parameters
8778
----------
8879
url : str, optional, default 'None;
8980
a url to use instead of the default
90-
tap_plus_handler : deprecated
91-
verbose : deprecated
9281
auth_session: `requests.Session` or `pyvo.auth.authsession.AuthSession`
9382
A existing authenticated session containing the appropriate
9483
credentials to be used by the client to communicate with the
@@ -98,10 +87,6 @@ def __init__(self, url=None, tap_plus_handler=None, verbose=None,
9887
-------
9988
Cadc object
10089
"""
101-
if tap_plus_handler:
102-
raise AttributeError('tap handler no longer supported')
103-
if verbose is not None:
104-
warnings.warn('verbose deprecated since version 0.4.0')
10590

10691
super(CadcClass, self).__init__()
10792
self.baseurl = url
@@ -210,19 +195,12 @@ def login(self, user=None, password=None, certificate_file=None):
210195
self.cadctap._session.cookies.set(
211196
CADC_COOKIE_PREFIX, cookie)
212197

213-
def logout(self, verbose=None):
198+
def logout(self):
214199
"""
215200
Logout. Anonymous access with all the subsequent use of the
216201
object. Note that the original session is not affected (in case
217202
it was passed when the object was first instantiated)
218-
219-
Parameters
220-
----------
221-
verbose : deprecated
222-
223203
"""
224-
if verbose is not None:
225-
warnings.warn('verbose deprecated since 0.4.0')
226204

227205
if isinstance(self._auth_session, pyvo.auth.AuthSession):
228206
# Remove the existing credentials (if any)
@@ -561,44 +539,38 @@ def get_data_urls(self, query_result, include_auxiliaries=False):
561539
result.append(service_def.access_url)
562540
return result
563541

564-
def get_tables(self, only_names=False, verbose=None):
542+
def get_tables(self, only_names=False):
565543
"""
566544
Gets all public tables
567545
568546
Parameters
569547
----------
570548
only_names : bool, optional, default False
571549
True to load table names only
572-
verbose : deprecated
573550
574551
Returns
575552
-------
576553
A list of table objects
577554
"""
578-
if verbose is not None:
579-
warnings.warn('verbose deprecated since 0.4.0')
580555
table_set = self.cadctap.tables
581556
if only_names:
582557
return list(table_set.keys())
583558
else:
584559
return list(table_set.values())
585560

586-
def get_table(self, table, verbose=None):
561+
def get_table(self, table):
587562
"""
588563
Gets the specified table
589564
590565
Parameters
591566
----------
592567
table : str, mandatory
593568
full qualified table name (i.e. schema name + table name)
594-
verbose : deprecated
595569
596570
Returns
597571
-------
598572
A table object
599573
"""
600-
if verbose is not None:
601-
warnings.warn('verbose deprecated since 0.4.0')
602574
tables = self.get_tables()
603575
for t in tables:
604576
if table == t.name:
@@ -683,67 +655,25 @@ def create_async(self, query, maxrec=None, uploads=None):
683655
return self.cadctap.submit_job(query, language='ADQL',
684656
uploads=uploads)
685657

686-
@deprecated('0.4.0', 'Use exec_sync or create_async instead')
687-
def run_query(self, query, operation, output_file=None,
688-
output_format="votable", verbose=None,
689-
background=False, upload_resource=None,
690-
upload_table_name=None):
691-
"""
692-
Runs a query
693-
694-
Parameters
695-
----------
696-
query : str, mandatory
697-
query to be executed
698-
operation : str, mandatory,
699-
'sync' or 'async' to run a synchronous or asynchronous job
700-
output_file : str, optional, default None
701-
file name where the results are saved if dumpToFile is True.
702-
If this parameter is not provided, the jobid is used instead
703-
output_format : str, optional, default 'votable'
704-
results format, 'csv', 'tsv' and 'votable'
705-
verbose : deprecated
706-
save_to_file : bool, optional, default 'False'
707-
if True, the results are saved in a file instead of using memory
708-
background : bool, optional, default 'False'
709-
when the job is executed in asynchronous mode,
710-
this flag specifies whether the execution will wait until results
711-
are available
712-
upload_resource : str, optional, default None
713-
resource to be uploaded to UPLOAD_SCHEMA
714-
upload_table_name : str, required if uploadResource is provided,
715-
default None
716-
resource temporary table name associated to the uploaded resource
717-
718-
Returns
719-
-------
720-
A Job object
721-
"""
722-
raise NotImplementedError('No longer supported. '
723-
'Use exec_sync or create_async instead.')
724-
725-
def load_async_job(self, jobid, verbose=None):
658+
def load_async_job(self, jobid):
726659
"""
727660
Loads an asynchronous job
728661
729662
Parameters
730663
----------
731664
jobid : str, mandatory
732665
job identifier
733-
verbose : deprecated
734666
735667
Returns
736668
-------
737669
A Job object
738670
"""
739-
if verbose is not None:
740-
warnings.warn('verbose deprecated since 0.4.0')
741671

742672
return pyvo.dal.AsyncTAPJob('{}/async/{}'.format(
743673
self.cadctap.baseurl, jobid), session=self._auth_session)
744674

745675
def list_async_jobs(self, phases=None, after=None, last=None,
746-
short_description=True, verbose=None):
676+
short_description=True):
747677
"""
748678
Returns all the asynchronous jobs
749679
@@ -760,14 +690,11 @@ def list_async_jobs(self, phases=None, after=None, last=None,
760690
corresponding to the TAP ShortJobDescription object (job ID, phase,
761691
run ID, owner ID and creation ID) whereas if False, a separate GET
762692
call to each job is performed for the complete job description
763-
verbose : deprecated
764693
765694
Returns
766695
-------
767696
A list of Job objects
768697
"""
769-
if verbose is not None:
770-
warnings.warn('verbose deprecated since 0.4.0')
771698

772699
return self.cadctap.get_job_list(phases=phases, after=after, last=last,
773700
short_description=short_description)

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')

0 commit comments

Comments
 (0)