Skip to content

Commit

Permalink
Improving test coverage of registry.regtap.
Browse files Browse the repository at this point in the history
(in an attempt to tackle #425).

This actually uncovered a bug in interpreting region_of_regard; since it
now comes out of VOTables, NULL and NaN are the same thing (since nobody
looks at region_of_regard, that certainly does not warrant a changelog
entry)

What is still uncovered is the deprecated ivoid2service, the obscure
region_of_regard, and some tedious piece of I/O.
  • Loading branch information
msdemlei committed Apr 26, 2023
1 parent a897483 commit bdbe74a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,11 @@ def region_of_regard(self):
by which a positional query against this resource should be "blurred"
in order to get an appropriate match.
"""
return float(self.get("region_of_regard", 0))
# we get NULLs as NaNs here
val = self["region_of_regard"]
if val!=val:
return None
return val

@property
def waveband(self):
Expand Down Expand Up @@ -734,15 +738,16 @@ def search(self, *args, **keys):
Raises
------
RuntimeError
DALServiceError
if the resource does not describe a searchable service.
"""
if not self.service:
try:
return self.service.search(*args, **keys)
except ValueError:
# I blindly assume the ValueError comes out of get_interface.
# But then that's likely enough.
raise dalq.DALServiceError(
"resource, {}, is not a searchable service".format(
self.short_name))

return self.service.search(*args, **keys)
f"Resource {self.ivoid} is not a searchable service")

def describe(self, verbose=False, width=78, file=None):
"""
Expand Down
31 changes: 31 additions & 0 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def test_record_fields(rt_pulsar_distance):
assert rec.content_types == ['catalog']
assert rec.source_format == "bibcode"
assert rec.source_value == "1993ApJS...88..529T"
assert rec.region_of_regard is None
assert rec.waveband == ['radio']
# access URL, standard_id and friends exercised in TestInterfaceSelection

Expand Down Expand Up @@ -453,6 +454,17 @@ def test_get_web_interface(self, flash_service):
assert (svc.access_url
== "http://dc.zah.uni-heidelberg.de/flashheros/q/web/form")

import webbrowser
orig_open = webbrowser.open
try:
open_args = []
webbrowser.open = lambda *args: open_args.append(args)
svc.search()
assert open_args == [
("http://dc.zah.uni-heidelberg.de/flashheros/q/web/form", 2)]
finally:
webbrowser.open = orig_open

def test_get_aux_interface(self, flash_service):
svc = flash_service.get_service("tap#aux")
assert (svc._baseurl
Expand Down Expand Up @@ -540,6 +552,22 @@ def test_sia2_aux(self):
assert rec.get_interface("sia2").access_url == 'http://sia2.example.com'
assert rec.get_interface("sia").access_url == 'http://sia.example.com'

def test_non_standard_interface(self):
intf = regtap.Interface("http://url", "", "", "")
assert intf.supports("ivo://ivoa.net/std/sia") == False

def test_supports_none(self):
intf = regtap.Interface("http://url", "", "", "")
assert intf.supports(None) == False

def test_non_searchable_service(self):
rec = _makeRegistryRecord()
with pytest.raises(dalq.DALServiceError) as excinfo:
rec.search()

assert str(excinfo.value) == (
"Resource ivo://pyvo/test_regtap.py is not a searchable service")


class _FakeResult:
"""A fake class just sufficient for giving dal.query.Record enough
Expand Down Expand Up @@ -623,6 +651,9 @@ def test_select_single_matching_service(self):
intf_roles=["", "std"])

assert (rsc.service._baseurl == "http://b")
# this makes sure caching the service obtained doesn't break
# things
assert (rsc.service._baseurl == "http://b")

def test_capless(self):
rsc = _makeRegistryRecord()
Expand Down

0 comments on commit bdbe74a

Please sign in to comment.