Skip to content

Commit 5e221bc

Browse files
authored
Merge pull request #2671 from nkphysics/kwarg-refactors-test-fixes
Cadc and Heasarc Kwarg refactors
2 parents 20be1ef + 6eb5dc4 commit 5e221bc

File tree

6 files changed

+32
-33
lines changed

6 files changed

+32
-33
lines changed

CHANGES.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Infrastructure, Utility and Other Changes and Additions
227227
-------------------------------------------------------
228228

229229
- Optional keyword arguments are now keyword only. [#1802, #2477, #2532,
230-
#2597, #2601, #2609, #2655, #2656, #2661]
230+
#2597, #2601, #2609, #2655, #2656, #2661, #2671]
231231

232232
- New function, ``utils.cleanup_downloads.cleanup_saved_downloads``, is
233233
added to help the testcleanup narrative in narrative documentations. [#2384]

astroquery/cadc/core.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class CadcClass(BaseQuery):
7070
CADCLOGIN_SERVICE_URI = conf.CADCLOGIN_SERVICE_URI
7171
TIMEOUT = conf.TIMEOUT
7272

73-
def __init__(self, url=None, auth_session=None):
73+
def __init__(self, *, url=None, auth_session=None):
7474
"""
7575
Initialize Cadc object
7676
@@ -123,10 +123,10 @@ def data_link_url(self):
123123
if not hasattr(self, '_data_link_url'):
124124
self._data_link_url = get_access_url(
125125
self.CADCDATALINK_SERVICE_URI,
126-
"ivo://ivoa.net/std/DataLink#links-1.0")
126+
capability="ivo://ivoa.net/std/DataLink#links-1.0")
127127
return self._data_link_url
128128

129-
def login(self, user=None, password=None, certificate_file=None):
129+
def login(self, *, user=None, password=None, certificate_file=None):
130130
"""
131131
login allows user to authenticate to the service. Both user/password
132132
and https client certificates are supported.
@@ -167,7 +167,7 @@ def login(self, user=None, password=None, certificate_file=None):
167167
self.cadctap._session.cert = certificate_file
168168
if user and password:
169169
login_url = get_access_url(self.CADCLOGIN_SERVICE_URI,
170-
'ivo://ivoa.net/std/UMS#login-0.1')
170+
capability='ivo://ivoa.net/std/UMS#login-0.1')
171171
if login_url is None:
172172
raise RuntimeError("No login URL")
173173
# need to login and get a cookie
@@ -223,7 +223,7 @@ def logout(self):
223223
'Do not know how to log out from custom session')
224224

225225
@class_or_instance
226-
def query_region_async(self, coordinates, radius=0.016666666666667*u.deg,
226+
def query_region_async(self, coordinates, *, radius=0.016666666666667*u.deg,
227227
collection=None,
228228
get_query_payload=False):
229229
"""
@@ -311,7 +311,7 @@ def get_collections(self):
311311
return collections
312312

313313
@class_or_instance
314-
def get_images(self, coordinates, radius,
314+
def get_images(self, coordinates, radius, *,
315315
collection=None,
316316
get_url_list=False,
317317
show_progress=False):
@@ -340,8 +340,8 @@ def get_images(self, coordinates, radius,
340340
str if returning urls).
341341
"""
342342

343-
filenames = self.get_images_async(coordinates, radius, collection,
344-
get_url_list, show_progress)
343+
filenames = self.get_images_async(coordinates, radius, collection=collection,
344+
get_url_list=get_url_list, show_progress=show_progress)
345345

346346
if get_url_list:
347347
return filenames
@@ -360,7 +360,7 @@ def get_images(self, coordinates, radius,
360360

361361
return images
362362

363-
def get_images_async(self, coordinates, radius, collection=None,
363+
def get_images_async(self, coordinates, radius, *, collection=None,
364364
get_url_list=False, show_progress=False):
365365
"""
366366
A coordinate-based query function that returns a list of
@@ -471,7 +471,7 @@ def get_image_list(self, query_result, coordinates, radius):
471471
return result
472472

473473
@class_or_instance
474-
def get_data_urls(self, query_result, include_auxiliaries=False):
474+
def get_data_urls(self, query_result, *, include_auxiliaries=False):
475475
"""
476476
Function to map the results of a CADC query into URLs to
477477
corresponding data that can be later downloaded.
@@ -538,7 +538,7 @@ def get_data_urls(self, query_result, include_auxiliaries=False):
538538
result.append(service_def.access_url)
539539
return result
540540

541-
def get_tables(self, only_names=False):
541+
def get_tables(self, *, only_names=False):
542542
"""
543543
Gets all public tables
544544
@@ -575,7 +575,7 @@ def get_table(self, table):
575575
if table == t.name:
576576
return t
577577

578-
def exec_sync(self, query, maxrec=None, uploads=None, output_file=None,
578+
def exec_sync(self, query, *, maxrec=None, uploads=None, output_file=None,
579579
output_format='votable'):
580580
"""
581581
Run a query and return the results or save them in an output_file
@@ -619,7 +619,7 @@ def exec_sync(self, query, maxrec=None, uploads=None, output_file=None,
619619
result.write(fname, format=output_format, overwrite=True)
620620
return result
621621

622-
def create_async(self, query, maxrec=None, uploads=None):
622+
def create_async(self, query, *, maxrec=None, uploads=None):
623623
"""
624624
Creates a TAP job to execute and returns it to the caller. The
625625
caller then can start the execution and monitor the job.
@@ -674,7 +674,7 @@ def load_async_job(self, jobid):
674674
return pyvo.dal.AsyncTAPJob('{}/async/{}'.format(
675675
self.cadctap.baseurl, jobid), session=self._auth_session)
676676

677-
def list_async_jobs(self, phases=None, after=None, last=None,
677+
def list_async_jobs(self, *, phases=None, after=None, last=None,
678678
short_description=True):
679679
"""
680680
Returns all the asynchronous jobs
@@ -701,7 +701,7 @@ def list_async_jobs(self, phases=None, after=None, last=None,
701701
return self.cadctap.get_job_list(phases=phases, after=after, last=last,
702702
short_description=short_description)
703703

704-
def _parse_result(self, result, verbose=None):
704+
def _parse_result(self, result, *, verbose=None):
705705
return result
706706

707707
def _args_to_payload(self, *args, **kwargs):
@@ -736,7 +736,7 @@ def decorate(func):
736736

737737

738738
@static_vars(caps={})
739-
def get_access_url(service, capability=None):
739+
def get_access_url(service, *, capability=None):
740740
"""
741741
Returns the URL corresponding to a service by doing a lookup in the cadc
742742
registry. It returns the access URL corresponding to cookie authentication.

astroquery/cadc/tests/test_cadctap.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_list_async_jobs():
123123

124124

125125
@patch('astroquery.cadc.core.get_access_url',
126-
Mock(side_effect=lambda x, y=None: 'https://some.url'))
126+
Mock(side_effect=lambda x, capability=None: 'https://some.url'))
127127
@patch('astroquery.cadc.core.pyvo.dal.TAPService.capabilities', []) # TAP capabilities not needed
128128
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService.capabilities', []) # DL capabilities not needed
129129
def test_auth():
@@ -135,7 +135,7 @@ def test_auth():
135135
password = 'password'
136136
cert = 'cert'
137137
with pytest.raises(AttributeError):
138-
cadc.login(None, None, None)
138+
cadc.login(user=None, password=None, certificate_file=None)
139139
with pytest.raises(AttributeError):
140140
cadc.login(user=user)
141141
with pytest.raises(AttributeError):
@@ -205,11 +205,11 @@ def raise_for_status(self):
205205
warnings.filterwarnings("ignore", category=XMLParsedAsHTMLWarning)
206206

207207
assert 'https://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/argus/tables' == \
208-
cadc_core.get_access_url('mytap', 'ivo://ivoa.net/std/VOSI#tables-1.1')
208+
cadc_core.get_access_url('mytap', capability='ivo://ivoa.net/std/VOSI#tables-1.1')
209209

210210

211211
@patch('astroquery.cadc.core.get_access_url',
212-
Mock(side_effect=lambda x, y=None: 'https://some.url'))
212+
Mock(side_effect=lambda x, capability=None: 'https://some.url'))
213213
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService',
214214
Mock(return_value=Mock(capabilities=[]))) # DL capabilities not needed
215215
def test_get_data_urls():
@@ -259,7 +259,7 @@ class Result:
259259

260260

261261
@patch('astroquery.cadc.core.get_access_url',
262-
Mock(side_effect=lambda x, y=None: 'https://some.url'))
262+
Mock(side_effect=lambda x, capability=None: 'https://some.url'))
263263
def test_misc():
264264
cadc = Cadc()
265265

@@ -288,7 +288,7 @@ def test_misc():
288288

289289

290290
@patch('astroquery.cadc.core.get_access_url',
291-
Mock(side_effect=lambda x, y=None: 'https://some.url'))
291+
Mock(side_effect=lambda x, capability=None: 'https://some.url'))
292292
@patch('astroquery.cadc.core.pyvo.dal.TAPService',
293293
Mock(return_value=Mock(capabilities=[]))) # TAP capabilities not needed
294294
@patch('astroquery.cadc.core.pyvo.dal.adhoc.DatalinkService',
@@ -359,7 +359,7 @@ def __init__(self, **param_dict):
359359

360360

361361
@patch('astroquery.cadc.core.get_access_url',
362-
Mock(side_effect=lambda x, y=None: 'https://some.url'))
362+
Mock(side_effect=lambda x, capability=None: 'https://some.url'))
363363
def test_exec_sync(tmp_path):
364364
# save results in a file
365365
# create the VOTable result

astroquery/heasarc/core.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class HeasarcClass(BaseQuery):
3737
TIMEOUT = conf.timeout
3838
coord_systems = ['fk5', 'fk4', 'equatorial', 'galactic']
3939

40-
def query_async(self, request_payload, cache=True, url=None):
40+
def query_async(self, request_payload, *, cache=True, url=None):
4141
"""
4242
Submit a query based on a given request_payload. This allows detailed
4343
control of the query to be submitted.
@@ -50,7 +50,7 @@ def query_async(self, request_payload, cache=True, url=None):
5050
timeout=self.TIMEOUT, cache=cache)
5151
return response
5252

53-
def query_mission_list(self, cache=True, get_query_payload=False):
53+
def query_mission_list(self, *, cache=True, get_query_payload=False):
5454
"""
5555
Returns a list of all available mission tables with descriptions
5656
"""
@@ -76,7 +76,7 @@ def query_mission_list(self, cache=True, get_query_payload=False):
7676
data_start=3, data_end=-1)
7777
return table
7878

79-
def query_mission_cols(self, mission, cache=True, get_query_payload=False,
79+
def query_mission_cols(self, mission, *, cache=True, get_query_payload=False,
8080
**kwargs):
8181
"""
8282
Returns a list containing the names of columns that can be returned for
@@ -108,7 +108,7 @@ def query_mission_cols(self, mission, cache=True, get_query_payload=False,
108108

109109
return self._parse_result(response).colnames
110110

111-
def query_object_async(self, object_name, mission,
111+
def query_object_async(self, object_name, mission, *,
112112
cache=True, get_query_payload=False,
113113
**kwargs):
114114
"""
@@ -138,7 +138,7 @@ def query_object_async(self, object_name, mission,
138138
return self.query_async(request_payload, cache=cache)
139139

140140
def query_region_async(self, position: Union[coordinates.SkyCoord, str],
141-
mission, radius, cache=True, get_query_payload=False,
141+
mission, radius, *, cache=True, get_query_payload=False,
142142
**kwargs):
143143
"""
144144
Query around specific set of coordinates within a given mission
@@ -245,7 +245,7 @@ def _blank_table_fallback(self, data):
245245
warnings.warn(NoResultsWarning("No matching rows were found in the query."))
246246
return emptytable
247247

248-
def _parse_result(self, response, verbose=False):
248+
def _parse_result(self, response, *, verbose=False):
249249
# if verbose is False then suppress any VOTable related warnings
250250
if not verbose:
251251
commons.suppress_vo_warnings()

docs/cadc/cadc.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ cutout coordinates and radius.
188188
>>> from astropy import units as u
189189
>>> cadc = Cadc()
190190
>>> coords = '01h45m07.5s +23d18m00s'
191-
>>> radius = 0.1*u.deg
192-
>>> results = cadc.query_region(coords, radius, collection='CFHT')
191+
>>> results = cadc.query_region(coords, radius=0.1*u.deg, collection='CFHT')
193192
>>> filtered_results = results[results['time_exposure'] > 120.0]
194193
>>> image_list = cadc.get_image_list(filtered_results, coords, radius) # doctest: +IGNORE_WARNINGS
195194
>>> print(image_list) # doctest: +IGNORE_OUTPUT

docs/heasarc/heasarc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ tables listing the most recent INTEGRAL data.
263263
>>> table = heasarc.query_object('Crab', mission='integral_rev3_scw',
264264
... radius='361 degree', time="2022-12-01 .. 2022-12-31",
265265
... sortvar='START_DATE', resultmax=100000)
266-
>>> table.pprint()
266+
>>> table.pprint() # doctest: +IGNORE_OUTPUT
267267
SCW_ID SCW_VER SCW_TYPE ... GOOD_OMC DSIZE SEARCH_OFFSET_
268268
------------ ------- -------- ... -------- --------- -----------------
269269
258300400010 001 POINTING ... 0 123494400 5199.027 (CRAB)\n

0 commit comments

Comments
 (0)