Skip to content

Commit 2afc229

Browse files
committed
Formatting
1 parent 7989c73 commit 2afc229

File tree

2 files changed

+58
-46
lines changed

2 files changed

+58
-46
lines changed

pyvo/dal/adhoc.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ def iter_datalinks(self, preserve_order=False):
400400
def iter_get_cloud_params(
401401
self,
402402
provider: str,
403-
colname: str="cloud_access",
404-
verbose: bool=False,
403+
colname: str = "cloud_access",
404+
verbose: bool = False,
405405
**match_params
406406
):
407407
"""
@@ -416,7 +416,7 @@ def iter_get_cloud_params(
416416
verbose : bool, optional
417417
Whether to print debug text, by default False.
418418
**match_params : str, optional
419-
Further parameters on which to match beyond `provider`.
419+
Further parameters on which to match beyond provider.
420420
421421
Returns
422422
-------
@@ -430,15 +430,15 @@ def iter_get_cloud_params(
430430
products = dl_results.bysemantics("#this")
431431

432432
for jrow, row in enumerate(products):
433-
# if no colname column, there is nothing to do
433+
# if no colname column, there is nothing to do
434434
jsontxt = row._guess_cloud_column(colname=colname)
435435
if jsontxt:
436436
access_points = row.parse_json_params(
437437
json_txt=jsontxt,
438438
json_key=provider,
439439
verbose=verbose,
440440
**match_params
441-
)
441+
)
442442
access_points.add_column([jrow]*len(access_points), name="datalink_row", index=0)
443443
if jrow == 0:
444444
new_dl_table = access_points
@@ -462,6 +462,7 @@ def iter_get_cloud_params(
462462

463463
return new_table
464464

465+
465466
class DatalinkRecordMixin:
466467
"""
467468
Mixin for record classes, providing functionallity for datalink.
@@ -514,11 +515,11 @@ def getdataset(self, timeout=None):
514515
def parse_json_params(
515516
json_txt: str,
516517
json_key: str,
517-
verbose: bool=False,
518+
verbose: bool = False,
518519
**match_params
519-
):
520+
):
520521
"""Parse information stored as JSON by key
521-
522+
522523
Parameters
523524
----------
524525
json_txt : str
@@ -528,7 +529,7 @@ def parse_json_params(
528529
verbose : bool, optional
529530
Whether to print progress and errors, by default False
530531
**match_params : str, optional
531-
Further parameters on which to match beyond `json_key`.
532+
Further parameters on which to match beyond json_key.
532533
533534
Returns
534535
-------
@@ -540,7 +541,7 @@ def parse_json_params(
540541

541542
# init results table (avoiding adding import of astropy.table.Table)
542543
new_table = TableElement(VOTableFile()).to_table()
543-
544+
544545
jsonDict = json.loads(json_txt)
545546
if json_key not in jsonDict and verbose:
546547
print(f'No key "{json_key}" found in json_txt given.')
@@ -591,7 +592,7 @@ def _guess_cloud_column(self, colname="cloud_access"):
591592
if cloud_access:
592593
return cloud_access
593594

594-
cloud_access = self.getbyucd("meta.ref.cloudstorage")
595+
cloud_access = self.getbyucd("meta.ref.cloudstorage")
595596
if cloud_access:
596597
return cloud_access
597598

@@ -601,9 +602,9 @@ def get_cloud_params(
601602
colname: str = "cloud_access",
602603
verbose: bool = False,
603604
**match_params
604-
):
605+
):
605606
"""Parse cloud information stored as JSON by provider
606-
607+
607608
Parameters
608609
----------
609610
provider: str
@@ -613,8 +614,8 @@ def get_cloud_params(
613614
verbose: bool, optional
614615
If True, print progress and debug text, by default False
615616
**match_params
616-
Further parameters on which to match beyond `provider`.
617-
617+
Further parameters on which to match beyond provider.
618+
618619
Return
619620
------
620621
astropy.Table
@@ -625,17 +626,16 @@ def get_cloud_params(
625626
dl_results = self.getdatalink()
626627
products = dl_results.bysemantics("#this")
627628

628-
629629
for irow, row in enumerate(products):
630-
# if no colname column, there is nothing to do
630+
# if no colname column, there is nothing to do
631631
cloud_json = row._guess_cloud_column(colname=colname)
632632
if cloud_json:
633633
access_points = row.parse_json_params(
634634
json_txt=cloud_json,
635635
json_key=provider,
636636
verbose=verbose,
637637
**match_params
638-
)
638+
)
639639
access_points.add_column([irow]*len(access_points), name="datalink_row", index=0)
640640
if irow == 0:
641641
new_table = access_points
@@ -651,6 +651,7 @@ def get_cloud_params(
651651

652652
return new_table
653653

654+
654655
class DatalinkService(DALService, AvailabilityMixin, CapabilityMixin):
655656
"""
656657
a representation of a Datalink service

pyvo/dal/tests/test_datalink.py

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ def callback(request, context):
7676
) as matcher:
7777
yield matcher
7878

79+
7980
@pytest.fixture()
8081
def datalink_cloud1(mocker):
81-
def callback(request, context):
82+
def callback(request, context):
8283
dl_base = parse('pyvo/dal/tests/data/datalink/datalink.xml')
8384
dl_base_table = dl_base.get_first_table().to_table()
84-
cloud_access_str = '{"aws": {"bucket_name": "test", "key":"path/to/cloudfile.fits", "region": "us-west-2"}}'
85+
cloud_access_str = ('{"aws": {"bucket_name": "test", '
86+
'"key":"path/to/cloudfile.fits", "region": "us-west-2"}}')
8587
dl_base_table.add_column([cloud_access_str]*4, name='cloud_access')
8688
out = BytesIO()
8789
votable = from_table(dl_base_table)
@@ -94,14 +96,17 @@ def callback(request, context):
9496
) as matcher:
9597
yield matcher
9698

99+
97100
@pytest.fixture()
98101
def datalink_cloud2(mocker):
99-
def callback(request, context):
102+
def callback(request, context):
100103
dl_base = parse('pyvo/dal/tests/data/datalink/datalink.xml')
101104
dl_base_table = dl_base.get_first_table().to_table()
102105
cloud_access_str = ('{"aws": '
103-
'[{"bucket_name": "test", "key": "path/to/cloudfile.fits", "region": "us-west-2"}, '
104-
'{"bucket_name": "test", "key": "path/to/cloudfile2.fits", "region": "us-west-2"}]}')
106+
'[{"bucket_name": "test", '
107+
'"key": "path/to/cloudfile.fits", "region": "us-west-2"}, '
108+
'{"bucket_name": "test", '
109+
'"key": "path/to/cloudfile2.fits", "region": "us-west-2"}]}')
105110
dl_base_table.add_column([cloud_access_str]*4, name='cloud_access')
106111
out = BytesIO()
107112
votable = from_table(dl_base_table)
@@ -114,6 +119,7 @@ def callback(request, context):
114119
) as matcher:
115120
yield matcher
116121

122+
117123
@pytest.fixture()
118124
def obscore_datalink(mocker):
119125
def callback(request, context):
@@ -376,31 +382,32 @@ def test_no_datalink():
376382
with pytest.raises(DALServiceError, match="No datalink found for record."):
377383
result.getdatalink()
378384

385+
379386
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.E02")
380387
@pytest.mark.usefixtures('datalink_cloud1', 'datalink_cloud2', 'datalink_product')
381388
class TestJsonColumns:
382-
"""Tests for producing datalinks from tables containing links to
383-
datalink documents.
389+
"""Tests for parsing JSON in Records and Results columns.
384390
"""
385391

386392
res = testing.create_dalresults([
387-
{"name": "access_url", "datatype": "char", "arraysize": "*",
388-
"ucd": "meta.ref.url"},
389-
{"name": "access_format", "datatype": "char", "arraysize": "*",
390-
"utype": "meta.code.mime"},
391-
{"name": "cloud_access", "datatype": "char", "arraysize": "*",
392-
"utype": "adhoc:cloudstorage", "ucd": "meta.ref.cloudstorage"},],
393-
[("http://example.com/datalink-cloud1.xml",
394-
"application/x-votable+xml;content=datalink",
395-
'{"aws": {"bucket_name": "test", "key":"path/to/file1.fits", "region": "us-west-2"}}',),
396-
("http://example.com/datalink-cloud2.xml",
397-
"application/x-votable+xml;content=datalink",
398-
'{"aws": {"bucket_name": "test", "key":"path/to/file2.fits", "region": "us-west-2"}}',),
399-
("http://example.com/datalink.xml",
400-
"application/x-votable+xml;content=datalink",
401-
'{"aws": {"bucket_name": "test", "key":"path/to/file2.fits", "region": "us-west-2"}}',),],
402-
resultsClass=SIA2Results
403-
)
393+
{"name": "access_url", "datatype": "char", "arraysize": "*",
394+
"ucd": "meta.ref.url"},
395+
{"name": "access_format", "datatype": "char", "arraysize": "*",
396+
"utype": "meta.code.mime"},
397+
{"name": "cloud_access", "datatype": "char", "arraysize": "*",
398+
"utype": "adhoc:cloudstorage", "ucd": "meta.ref.cloudstorage"},],
399+
[("http://example.com/datalink-cloud1.xml",
400+
"application/x-votable+xml;content=datalink",
401+
'{"aws": {"bucket_name": "test", "key":"path/to/file1.fits", "region": "us-west-2"}}',),
402+
("http://example.com/datalink-cloud2.xml",
403+
"application/x-votable+xml;content=datalink",
404+
'{"aws": {"bucket_name": "test", "key":"path/to/file2.fits", "region": "us-west-2"}}',),
405+
("http://example.com/datalink.xml",
406+
"application/x-votable+xml;content=datalink",
407+
'{"aws": {"bucket_name": "test", "key":"path/to/file2.fits", "region": "us-west-2"}}',),],
408+
resultsClass=SIA2Results
409+
)
410+
404411
def test_record_w_json(self):
405412

406413
jsontxt = '{"aws": {"bucket_name": "test", "key":"path/to/file1.fits", "region": "us-west-2"}}'
@@ -413,11 +420,14 @@ def test_extra_key(self):
413420
# Check that giving extra kwargs matches parameters
414421
jsontxt = '{"aws": {"bucket_name": "test", "key":"path/to/file1.fits", "region": "us-west-2"}}'
415422
parsed_json_matches0 = self.res[0].parse_json_params(json_txt=jsontxt, json_key="aws")
416-
parsed_json_matches1 = self.res[0].parse_json_params(json_txt=jsontxt, json_key="aws", region="us-west-2")
423+
parsed_json_matches1 = self.res[0].parse_json_params(json_txt=jsontxt,
424+
json_key="aws", region="us-west-2")
417425

418426
assert parsed_json_matches0 == parsed_json_matches1
419427

420-
parsed_json_matches2 = self.res[0].parse_json_params(json_txt=jsontxt, json_key="aws", region="us-west-1")
428+
parsed_json_matches2 = self.res[0].parse_json_params(json_txt=jsontxt,
429+
json_key="aws",
430+
region="us-west-1")
421431
assert len(parsed_json_matches2) == 0
422432

423433
def test_datalink_json(self):
@@ -444,7 +454,9 @@ def test_existing_colname(self):
444454

445455
def no_column_in_datalink(self, capsys):
446456
# All column guesses come back empty
447-
parsed_cloud_params = self.res[1].get_cloud_params(provider="aws", colname="cloud_access", verbose=True)
457+
parsed_cloud_params = self.res[1].get_cloud_params(provider="aws",
458+
colname="cloud_access",
459+
verbose=True)
448460
assert "No column cloud_access" in capsys
449461
assert parsed_cloud_params is None
450462

@@ -463,4 +475,3 @@ def test_iter_datalink_json(self):
463475
assert parsed_json_matches[2]["record_row"] == 1
464476
assert parsed_json_matches[2]["datalink_row"] == 0
465477
assert parsed_json_matches[2]["key"] == "path/to/cloudfile2.fits"
466-

0 commit comments

Comments
 (0)