Skip to content

Commit

Permalink
Making tests using the messenger vocabulary non-remote.
Browse files Browse the repository at this point in the history
The messenger_vocabulary fixture should have made them non-remote, but
I've never actually tested that.  It now turns out that astropy.data doesn't
use requests and hence my nice requests mocker just didn't work.

I've now replaced it by code seeding astropy.data's cache.  This is a
pattern we ought to use whenever code uses IVOA vocabularies.  I wonder
where we should document this?
  • Loading branch information
msdemlei committed Jun 2, 2022
1 parent ae43aa1 commit cc2967c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyvo/registry/regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def standard_id(self):

def access_modes(self):
"""
returns a list of interface identifiers available on
returns a set of interface identifiers available on
this resource.
For standard interfaces, get_service will return a service
Expand Down
8 changes: 6 additions & 2 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from astropy.utils.data import get_pkg_data_contents

from .commonfixtures import messenger_vocabulary


get_pkg_data_contents = partial(
get_pkg_data_contents, package=__package__, encoding='binary')
Expand Down Expand Up @@ -274,8 +276,10 @@ def test_servicetype():
regsearch(servicetype='table')


@pytest.mark.remote_data
@pytest.mark.usefixtures('waveband_fixture', 'capabilities')
@pytest.mark.usefixtures(
'waveband_fixture',
'capabilities',
'messenger_vocabulary')
def test_waveband():
regsearch(waveband='optical')

Expand Down
18 changes: 4 additions & 14 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@
from pyvo.registry import rtcons
from pyvo.dal import query as dalq


@pytest.fixture()
def messenger_vocabulary(mocker):
def callback(request, context):
return get_pkg_data_contents('data/messenger.desise')

with mocker.register_uri(
'GET', 'http://www.ivoa.net/rdf/messenger', content=callback
) as matcher:
yield matcher
from .commonfixtures import messenger_vocabulary


class TestAbstractConstraint:
Expand Down Expand Up @@ -128,7 +119,6 @@ def test_legacy_term(self):


@pytest.mark.usefixtures('messenger_vocabulary')
@pytest.mark.remote_data
class TestWavebandConstraint:
def test_basic(self):
assert (rtcons.Waveband("Infrared", "EUV").get_search_condition()
Expand Down Expand Up @@ -301,23 +291,23 @@ def where_clause_for(*args, **kwargs):
return rtcons.build_regtap_query(cons
).split("\nWHERE\n", 1)[1].split("\nGROUP BY\n")[0]

@pytest.mark.remote_data
@pytest.mark.usefixtures('messenger_vocabulary')
def test_from_constraints(self):
assert self.where_clause_for(
rtcons.Waveband("EUV"),
rtcons.Author("%Hubble%")
) == ("(1 = ivo_hashlist_has(rr.resource.waveband, 'euv'))\n"
" AND (role_name LIKE '%Hubble%' AND base_role='creator')")

@pytest.mark.remote_data
@pytest.mark.usefixtures('messenger_vocabulary')
def test_from_keywords(self):
assert self.where_clause_for(
waveband="EUV",
author="%Hubble%"
) == ("(1 = ivo_hashlist_has(rr.resource.waveband, 'euv'))\n"
" AND (role_name LIKE '%Hubble%' AND base_role='creator')")

@pytest.mark.remote_data
@pytest.mark.usefixtures('messenger_vocabulary')
def test_mixed(self):
assert self.where_clause_for(
rtcons.Waveband("EUV"),
Expand Down

0 comments on commit cc2967c

Please sign in to comment.