Skip to content

Commit

Permalink
feat: add source_value and alt_identifier to the verbose output pf de…
Browse files Browse the repository at this point in the history
…scribe

the tests are also adapted to the renewed versions of the xml data files
  • Loading branch information
ManonMarchand committed Oct 2, 2023
1 parent 8b8624d commit d055bb9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
1.5 (unreleased)
================

- Added the ``source_value`` and ``alt_identifier`` information to the verbose
output of ``describe()`` in ``regtap``. [#492]

- Added convenience method DALResults.to_qtable() that returns an
astropy.table.QTable object. [#384]

Expand Down
24 changes: 20 additions & 4 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ class RegistryResource(dalq.Record):
(f"\n ivo_string_agg(COALESCE(intf_type, ''), '{TOKEN_SEP}')",
"intf_types"),
(f"\n ivo_string_agg(COALESCE(intf_role, ''), '{TOKEN_SEP}')",
"intf_roles"), ]
"intf_roles"),
"alt_identifier"]

def __init__(self, results, index, session=None):
dalq.Record.__init__(self, results, index, session)
Expand Down Expand Up @@ -534,6 +535,14 @@ def reference_url(self):
"""
return self.get("reference_url", decode=True)

@property
def alt_identifier(self):
"""Alternative identifier.
It is often used to provide the resource associated DOI.
"""
return self.get("alt_identifier", decode=True)

@property
def creators(self):
"""
Expand Down Expand Up @@ -789,7 +798,9 @@ def describe(self, verbose=False, width=78, file=None):
----------
verbose : bool
If false (default), only user-oriented information is
printed; if true, additional information will be printed
printed; if true, additional information -- reference url,
reference to the related article, and alternative identifier
(often a DOI) -- will be printed if available for this resource.
as well.
width : int
Format the description with given character-width.
Expand All @@ -806,7 +817,7 @@ def describe(self, verbose=False, width=78, file=None):
if len(self._mapping["access_urls"]) == 1:
print("Base URL: " + self.access_url, file=file)
else:
print("Multi-capabilty service -- use get_service()", file=file)
print("Multi-capability service -- use get_service()", file=file)

if self.res_description:
print(file=file)
Expand All @@ -824,8 +835,13 @@ def describe(self, verbose=False, width=78, file=None):
file=file)

if verbose:
print("\n More info:")
if self.reference_url:
print("More info: " + self.reference_url, file=file)
print("Reference url: " + self.reference_url, file=file)
if self.alt_identifier:
print(f"Alternative identifier: {self.alt_identifier}", file=file)
if self.source_value:
print(f"Source: {self.source_value}", file=file)

def get_contact(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion pyvo/registry/rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def build_regtap_query(constraints):
serialized.append("(" + constraint.get_search_condition() + ")")
extra_tables |= set(constraint._extra_tables)

joined_tables = ["rr.resource", "rr.capability", "rr.interface"
joined_tables = ["rr.resource", "rr.capability", "rr.interface",
"rr.alt_identifier"
] + list(extra_tables)

# see comment in regtap.RegistryResource for the following
Expand Down
19 changes: 10 additions & 9 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def test_to_table(multi_interface_fixture, capabilities):
assert (t["description"][0][:40]
== 'Spectra from the Flash and Heros Echelle')
assert (t["interfaces"][0]
== 'datalink#links-1.0, soda#sync-1.0, ssa, tap#aux, web')
== 'datalink#links-1.1, soda#sync-1.0, ssa, tap#aux, web')


@pytest.fixture(name='rt_pulsar_distance')
Expand All @@ -378,7 +378,7 @@ def test_record_fields(rt_pulsar_distance):
assert rec.res_title == "Catalog of 558 Pulsars"
assert rec.content_levels == ['research']
assert rec.res_description[:20] == "The catalogue is an up-to-date"[:20]
assert rec.reference_url == "http://cdsarc.unistra.fr/cgi-bin/cat/VII/156"
assert rec.reference_url == "https://cdsarc.cds.unistra.fr/viz-bin/cat/VII/156"
assert rec.creators == ['Taylor J.H.', ' Manchester R.N.', ' Lyne A.G.']
assert rec.content_types == ['catalog']
assert rec.source_format == "bibcode"
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_out_of_range(self, rt_pulsar_distance):
with pytest.raises(IndexError) as excinfo:
rt_pulsar_distance[40320]
assert (str(excinfo.value)
== "index 40320 is out of bounds for axis 0 with size 23")
== f"index 40320 is out of bounds for axis 0 with size {len(rt_pulsar_distance)}")

def test_bad_key(self, rt_pulsar_distance):
with pytest.raises(KeyError) as excinfo:
Expand Down Expand Up @@ -435,15 +435,15 @@ def test_exactly_one_result(self):

def test_access_modes(self, flash_service):
assert set(flash_service.access_modes()) == {
'datalink#links-1.0', 'soda#sync-1.0', 'ssa', 'tap#aux',
'datalink#links-1.1', 'soda#sync-1.0', 'ssa', 'tap#aux',
'web'}

def test_standard_id_multi(self, flash_service):
with pytest.raises(dalq.DALQueryError) as excinfo:
_ = flash_service.standard_id

assert str(excinfo.value) == ("This resource supports several"
" standards (datalink#links-1.0, soda#sync-1.0, ssa,"
" standards (datalink#links-1.1, soda#sync-1.0, ssa,"
" tap#aux, web). Use get_service or restrict your query"
" using Servicetype.")

Expand Down Expand Up @@ -722,11 +722,12 @@ def test_describe_multi(self, flash_service):
output = out.getvalue()

assert "Flash/Heros SSAP" in output
assert ("Access modes: datalink#links-1.0, soda#sync-1.0,"
assert ("Access modes: datalink#links-1.1, soda#sync-1.0,"
" ssa, tap#aux, web" in output)
assert "Multi-capabilty service" in output

assert "More info: http://dc.zah" in output
assert "Multi-capability service" in output
assert "Source: 1996A&A...312..539S" in output
assert "Reference url: http://dc.zah" in output
assert "Alternative identifier: doi:10.21938/" in output

def test_no_access_url(self):
rsc = _makeRegistryRecord(
Expand Down
6 changes: 4 additions & 2 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ def test_expected_columns(self):
"\n ivo_string_agg(COALESCE(access_url, ''), ':::py VO sep:::') AS access_urls, "
"\n ivo_string_agg(COALESCE(standard_id, ''), ':::py VO sep:::') AS standard_ids, "
"\n ivo_string_agg(COALESCE(intf_type, ''), ':::py VO sep:::') AS intf_types, "
"\n ivo_string_agg(COALESCE(intf_role, ''), ':::py VO sep:::') AS intf_roles")
"\n ivo_string_agg(COALESCE(intf_role, ''), ':::py VO sep:::') AS intf_roles, "
"alt_identifier")

def test_group_by_columns(self):
# Again, this will break as regtap.RegistryResource.expected_columns
Expand All @@ -390,4 +391,5 @@ def test_group_by_columns(self):
"source_format, "
"source_value, "
"region_of_regard, "
"waveband")
"waveband, "
"alt_identifier")

0 comments on commit d055bb9

Please sign in to comment.