1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
-
3
-
4
2
import json
5
3
import os
6
4
import sys
16
14
17
15
from ...exceptions import NoResultsWarning
18
16
from ...utils .testing_tools import MockResponse
19
- from ..core import NasaExoplanetArchive , conf , InvalidTableError
17
+ from ..core import NasaExoplanetArchiveClass , conf , InvalidTableError
20
18
try :
21
19
from unittest .mock import Mock , patch , PropertyMock
22
20
except ImportError :
@@ -122,12 +120,14 @@ def patch_get(request): # pragma: nocover
122
120
123
121
124
122
def test_regularize_object_name (patch_get ):
125
- NasaExoplanetArchive ._tap_tables = ['list' ]
126
- assert NasaExoplanetArchive ._regularize_object_name ("kepler 2" ) == "HAT-P-7"
127
- assert NasaExoplanetArchive ._regularize_object_name ("kepler 1 b" ) == "TrES-2 b"
123
+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
124
+
125
+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
126
+ assert NasaExoplanetArchiveMock ._regularize_object_name ("kepler 2" ) == "HAT-P-7"
127
+ assert NasaExoplanetArchiveMock ._regularize_object_name ("kepler 1 b" ) == "TrES-2 b"
128
128
129
129
with pytest .warns (NoResultsWarning ) as warning :
130
- NasaExoplanetArchive ._regularize_object_name ("not a planet" )
130
+ NasaExoplanetArchiveMock ._regularize_object_name ("not a planet" )
131
131
assert "No aliases found for name: 'not a planet'" == str (warning [0 ].message )
132
132
133
133
@@ -136,44 +136,48 @@ def test_backwards_compat(patch_get):
136
136
These are the tests from the previous version of this interface.
137
137
They query old tables by default and should return InvalidTableError.
138
138
"""
139
- NasaExoplanetArchive ._tap_tables = ['list' ]
139
+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
140
+
141
+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
140
142
141
143
# test_hd209458b_exoplanets_archive
142
144
with pytest .warns (AstropyDeprecationWarning ):
143
145
with pytest .raises (InvalidTableError ) as error :
144
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
146
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
145
147
assert "replaced" in str (error )
146
148
147
149
# test_hd209458b_exoplanet_archive_coords
148
150
with pytest .warns (AstropyDeprecationWarning ):
149
151
with pytest .raises (InvalidTableError ) as error :
150
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
152
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
151
153
assert "replaced" in str (error )
152
154
153
155
# test_hd209458_stellar_exoplanet
154
156
with pytest .warns (AstropyDeprecationWarning ):
155
157
with pytest .raises (InvalidTableError ) as error :
156
- params = NasaExoplanetArchive .query_star ("HD 209458" )
158
+ NasaExoplanetArchiveMock .query_star ("HD 209458" )
157
159
assert "replaced" in str (error )
158
160
159
161
# test_hd136352_stellar_exoplanet_archive
160
162
with pytest .warns (AstropyDeprecationWarning ):
161
163
with pytest .raises (InvalidTableError ) as error :
162
- params = NasaExoplanetArchive .query_star ("HD 136352" )
164
+ NasaExoplanetArchiveMock .query_star ("HD 136352" )
163
165
assert "replaced" in str (error )
164
166
165
167
# test_exoplanet_archive_query_all_columns
166
168
with pytest .warns (AstropyDeprecationWarning ):
167
169
with pytest .raises (InvalidTableError ) as error :
168
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " , all_columns = True )
170
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " , all_columns = True )
169
171
assert "replaced" in str (error )
170
172
171
173
172
174
@pytest .mark .filterwarnings ("error" )
173
175
@pytest .mark .parametrize ("table,query" , API_TABLES )
174
176
def test_api_tables (patch_get , table , query ):
175
- NasaExoplanetArchive ._tap_tables = ['list' ]
176
- data = NasaExoplanetArchive .query_criteria (table , select = "*" , ** query )
177
+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
178
+
179
+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
180
+ data = NasaExoplanetArchiveMock .query_criteria (table , select = "*" , ** query )
177
181
assert len (data ) > 0
178
182
179
183
# Check that the units were fixed properly
@@ -185,7 +189,7 @@ def test_api_tables(patch_get, table, query):
185
189
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
186
190
Mock (side_effect = lambda x : 'https://some.url' ))
187
191
def test_query_object ():
188
- nasa_exoplanet_archive = NasaExoplanetArchive ()
192
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
189
193
190
194
def mock_run_query (object_name = "K2-18 b" , table = "pscomppars" , select = "pl_name,disc_year,discoverymethod,ra,dec" ):
191
195
assert object_name == "K2-18 b"
@@ -207,7 +211,7 @@ def mock_run_query(object_name="K2-18 b", table="pscomppars", select="pl_name,di
207
211
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
208
212
Mock (side_effect = lambda x : 'https://some.url' ))
209
213
def test_query_region ():
210
- nasa_exoplanet_archive = NasaExoplanetArchive ()
214
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
211
215
212
216
def mock_run_query (table = "ps" , select = 'pl_name,ra,dec' , coordinates = SkyCoord (ra = 172.56 * u .deg , dec = 7.59 * u .deg ), radius = 1.0 * u .deg ):
213
217
assert table == "ps"
@@ -224,7 +228,7 @@ def mock_run_query(table="ps", select='pl_name,ra,dec', coordinates=SkyCoord(ra=
224
228
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
225
229
Mock (side_effect = lambda x : 'https://some.url' ))
226
230
def test_query_criteria ():
227
- nasa_exoplanet_archive = NasaExoplanetArchive ()
231
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
228
232
229
233
def mock_run_query (table = "ps" , select = 'pl_name,discoverymethod,dec' , where = "discoverymethod like 'Microlensing' and dec > 0" ):
230
234
assert table == "ps"
@@ -243,7 +247,7 @@ def mock_run_query(table="ps", select='pl_name,discoverymethod,dec', where="disc
243
247
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
244
248
Mock (side_effect = lambda x : 'https://some.url' ))
245
249
def test_get_query_payload ():
246
- nasa_exoplanet_archive = NasaExoplanetArchive ()
250
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
247
251
248
252
def mock_run_query (table = "ps" , get_query_payload = True , select = "count(*)" , where = "disc_facility like '%TESS%'" ):
249
253
assert table == "ps"
@@ -263,7 +267,7 @@ def mock_run_query(table="ps", get_query_payload=True, select="count(*)", where=
263
267
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
264
268
Mock (side_effect = lambda x : 'https://some.url' ))
265
269
def test_select ():
266
- nasa_exoplanet_archive = NasaExoplanetArchive ()
270
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
267
271
268
272
def mock_run_query (table = "ps" , select = ["hostname" , "pl_name" ], where = "hostname='Kepler-11'" , get_query_payload = True ):
269
273
assert table == "ps"
@@ -281,7 +285,7 @@ def mock_run_query(table="ps", select=["hostname", "pl_name"], where="hostname='
281
285
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
282
286
Mock (side_effect = lambda x : 'https://some.url' ))
283
287
def test_get_tap_tables ():
284
- nasa_exoplanet_archive = NasaExoplanetArchive ()
288
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
285
289
286
290
def mock_run_query (url = conf .url_tap ):
287
291
assert url == conf .url_tap
0 commit comments