Skip to content

Commit 566354e

Browse files
rickynilssonbsipocz
authored andcommitted
Clean up mock tests and try fetching TAP tables again
1 parent dd40101 commit 566354e

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

astroquery/nasa_exoplanet_archive/core.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io
66
import re
77
import warnings
8+
import pytest
89

910
# Import various astropy modules
1011
import astropy.coordinates as coord
@@ -96,12 +97,18 @@ def get_access_url(service='tap'):
9697
url = conf.url_api
9798
return url
9899

99-
# def get_tap_tables(url):
100-
# """Tables accessed by API are gradually migrating to TAP service. Generate current list of tables in TAP."""
101-
# tap = pyvo.dal.tap.TAPService(baseurl=url)
102-
# response = tap.search(query="select * from TAP_SCHEMA.tables", language="ADQL")
103-
# tables = [table for table in response["table_name"].data if "TAP_SCHEMA." not in table]
104-
# return tables
100+
101+
@pytest.mark.remote_data
102+
def get_tap_tables(url):
103+
"""Tables accessed by API are gradually migrating to TAP service. Generate current list of tables in TAP."""
104+
tap = pyvo.dal.tap.TAPService(baseurl=url)
105+
response = tap.search(query="select * from TAP_SCHEMA.tables", language="ADQL")
106+
tables = [table for table in response["table_name"].data if "TAP_SCHEMA." not in table]
107+
return tables
108+
109+
110+
TAP_TABLES = get_tap_tables(conf.url_tap)
111+
105112

106113
class InvalidTableError(InvalidQueryError):
107114
"""Exception thrown if the given table is not recognized by the Exoplanet Archive Servers"""
@@ -195,7 +202,7 @@ def query_criteria_async(self, table, get_query_payload=False, cache=None, **cri
195202
if cache is None:
196203
cache = self.CACHE
197204

198-
if table in ['ps', 'pscomppars']:
205+
if table in TAP_TABLES:
199206
tap = pyvo.dal.tap.TAPService(baseurl=self.URL_TAP)
200207
# construct query from table and request_payload (including format)
201208
tap_query = self._request_to_sql(request_payload)
@@ -335,7 +342,7 @@ def query_object_async(self, object_name, *, table="ps", get_query_payload=False
335342
"Any filters using the 'where' argument are ignored in ``query_object``. Consider using ``query_criteria`` instead.",
336343
InputWarning,
337344
)
338-
if table in ['ps', 'pscomppars']:
345+
if table in TAP_TABLES:
339346
criteria["where"] = "hostname='{1}' OR {0}name='{1}'".format(prefix, object_name.strip())
340347
else:
341348
criteria["where"] = "{0}hostname='{1}' OR {0}name='{1}'".format(prefix, object_name.strip())

astroquery/nasa_exoplanet_archive/tests/test_nasa_exoplanet_archive.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
]
8585

8686

87-
@pytest.mark.remote_data
8887
def mock_get(self, method, url, *args, **kwargs): # pragma: nocover
8988
assert url == conf.url_api
9089

@@ -126,7 +125,6 @@ def mock_get(self, method, url, *args, **kwargs): # pragma: nocover
126125
return MockResponse(data.encode("utf-8"))
127126

128127

129-
@pytest.mark.remote_data
130128
@pytest.fixture
131129
def patch_get(request): # pragma: nocover
132130
try:
@@ -140,7 +138,6 @@ def patch_get(request): # pragma: nocover
140138
return mp
141139

142140

143-
@pytest.mark.remote_data
144141
def test_regularize_object_name(patch_get):
145142
assert NasaExoplanetArchive._regularize_object_name("kepler 2") == "HAT-P-7"
146143
assert NasaExoplanetArchive._regularize_object_name("kepler 1 b") == "TrES-2 b"
@@ -150,7 +147,6 @@ def test_regularize_object_name(patch_get):
150147
assert "No aliases found for name: 'not a planet'" == str(warning[0].message)
151148

152149

153-
@pytest.mark.remote_data
154150
def test_backwards_compat(patch_get):
155151
"""
156152
These are the tests from the previous version of this interface.
@@ -188,7 +184,6 @@ def test_backwards_compat(patch_get):
188184
assert "replaced" in str(error)
189185

190186

191-
@pytest.mark.remote_data
192187
@pytest.mark.filterwarnings("error")
193188
@pytest.mark.parametrize("table,query", API_TABLES)
194189
def test_api_tables(patch_get, table, query):
@@ -201,7 +196,6 @@ def test_api_tables(patch_get, table, query):
201196

202197

203198
# Mock tests on TAP service below
204-
@pytest.mark.remote_data
205199
@patch('astroquery.nasa_exoplanet_archive.core.get_access_url',
206200
Mock(side_effect=lambda x: 'https://some.url'))
207201
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
@@ -227,7 +221,6 @@ def mock_run_query(object_name="K2-18 b", table="pscomppars", select="pl_name,di
227221
assert response['dec'] == [7.5878315] * u.deg
228222

229223

230-
@pytest.mark.remote_data
231224
@patch('astroquery.nasa_exoplanet_archive.core.get_access_url',
232225
Mock(side_effect=lambda x: 'https://some.url'))
233226
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')
@@ -247,7 +240,6 @@ def mock_run_query(table="ps", select='pl_name,ra,dec', coordinates=SkyCoord(ra=
247240
assert 'K2-18 b' in response['pl_name']
248241

249242

250-
@pytest.mark.remote_data
251243
@patch('astroquery.nasa_exoplanet_archive.core.get_access_url',
252244
Mock(side_effect=lambda x: 'https://some.url'))
253245
@pytest.mark.skipif(not pyvo_OK, reason='not pyvo_OK')

0 commit comments

Comments
 (0)