diff --git a/pyvo/registry/regtap.py b/pyvo/registry/regtap.py index 4fb5f2cbe..d07648946 100644 --- a/pyvo/registry/regtap.py +++ b/pyvo/registry/regtap.py @@ -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): @@ -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): """ diff --git a/pyvo/registry/tests/test_regtap.py b/pyvo/registry/tests/test_regtap.py index a534c7057..1aa2c1305 100644 --- a/pyvo/registry/tests/test_regtap.py +++ b/pyvo/registry/tests/test_regtap.py @@ -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 @@ -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 @@ -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 @@ -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()