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
7
5
from urllib .parse import urlencode
8
6
9
7
import astropy .units as u
10
- from astropy .io .ascii import write as ap_write
11
- from astroquery .utils .commons import parse_coordinates
12
- from astropy .table import Table as AstroTable
13
- import numpy as np
14
8
import pkg_resources
15
9
import pytest
16
10
import requests
17
- try :
18
- pyvo_OK = True
19
- from pyvo .auth import authsession
20
- except ImportError :
21
- pyvo_OK = False
22
- pytest .skip ("Install pyvo for the nasa_exoplanet_archive module." , allow_module_level = True )
11
+
23
12
from astropy .coordinates import SkyCoord
24
- from astropy .tests .helper import assert_quantity_allclose
25
13
from astropy .utils .exceptions import AstropyDeprecationWarning
26
14
27
- from ...exceptions import InputWarning , InvalidQueryError , NoResultsWarning
15
+ from ...exceptions import NoResultsWarning
28
16
from ...utils .testing_tools import MockResponse
29
- from ..core import NasaExoplanetArchive , conf , InvalidTableError
17
+ from ..core import NasaExoplanetArchiveClass , conf , InvalidTableError
30
18
try :
31
19
from unittest .mock import Mock , patch , PropertyMock
32
20
except ImportError :
@@ -132,12 +120,14 @@ def patch_get(request): # pragma: nocover
132
120
133
121
134
122
def test_regularize_object_name (patch_get ):
135
- NasaExoplanetArchive ._tap_tables = ['list' ]
136
- assert NasaExoplanetArchive ._regularize_object_name ("kepler 2" ) == "HAT-P-7"
137
- 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"
138
128
139
129
with pytest .warns (NoResultsWarning ) as warning :
140
- NasaExoplanetArchive ._regularize_object_name ("not a planet" )
130
+ NasaExoplanetArchiveMock ._regularize_object_name ("not a planet" )
141
131
assert "No aliases found for name: 'not a planet'" == str (warning [0 ].message )
142
132
143
133
@@ -146,44 +136,47 @@ def test_backwards_compat(patch_get):
146
136
These are the tests from the previous version of this interface.
147
137
They query old tables by default and should return InvalidTableError.
148
138
"""
149
- NasaExoplanetArchive ._tap_tables = ['list' ]
139
+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
140
+
141
+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
150
142
151
143
# test_hd209458b_exoplanets_archive
152
144
with pytest .warns (AstropyDeprecationWarning ):
153
145
with pytest .raises (InvalidTableError ) as error :
154
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
146
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
155
147
assert "replaced" in str (error )
156
148
157
149
# test_hd209458b_exoplanet_archive_coords
158
150
with pytest .warns (AstropyDeprecationWarning ):
159
151
with pytest .raises (InvalidTableError ) as error :
160
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
152
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
161
153
assert "replaced" in str (error )
162
154
163
155
# test_hd209458_stellar_exoplanet
164
156
with pytest .warns (AstropyDeprecationWarning ):
165
157
with pytest .raises (InvalidTableError ) as error :
166
- params = NasaExoplanetArchive .query_star ("HD 209458" )
158
+ NasaExoplanetArchiveMock .query_star ("HD 209458" )
167
159
assert "replaced" in str (error )
168
160
169
161
# test_hd136352_stellar_exoplanet_archive
170
162
with pytest .warns (AstropyDeprecationWarning ):
171
163
with pytest .raises (InvalidTableError ) as error :
172
- params = NasaExoplanetArchive .query_star ("HD 136352" )
164
+ NasaExoplanetArchiveMock .query_star ("HD 136352" )
173
165
assert "replaced" in str (error )
174
166
175
167
# test_exoplanet_archive_query_all_columns
176
168
with pytest .warns (AstropyDeprecationWarning ):
177
169
with pytest .raises (InvalidTableError ) as error :
178
- params = NasaExoplanetArchive .query_planet ("HD 209458 b " , all_columns = True )
170
+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " , all_columns = True )
179
171
assert "replaced" in str (error )
180
172
181
173
182
- @pytest .mark .filterwarnings ("error" )
183
174
@pytest .mark .parametrize ("table,query" , API_TABLES )
184
175
def test_api_tables (patch_get , table , query ):
185
- NasaExoplanetArchive ._tap_tables = ['list' ]
186
- data = NasaExoplanetArchive .query_criteria (table , select = "*" , ** query )
176
+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
177
+
178
+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
179
+ data = NasaExoplanetArchiveMock .query_criteria (table , select = "*" , ** query )
187
180
assert len (data ) > 0
188
181
189
182
# Check that the units were fixed properly
@@ -194,9 +187,8 @@ def test_api_tables(patch_get, table, query):
194
187
# Mock tests on TAP service below
195
188
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
196
189
Mock (side_effect = lambda x : 'https://some.url' ))
197
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
198
190
def test_query_object ():
199
- nasa_exoplanet_archive = NasaExoplanetArchive ()
191
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
200
192
201
193
def mock_run_query (object_name = "K2-18 b" , table = "pscomppars" , select = "pl_name,disc_year,discoverymethod,ra,dec" ):
202
194
assert object_name == "K2-18 b"
@@ -217,9 +209,8 @@ def mock_run_query(object_name="K2-18 b", table="pscomppars", select="pl_name,di
217
209
218
210
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
219
211
Mock (side_effect = lambda x : 'https://some.url' ))
220
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
221
212
def test_query_region ():
222
- nasa_exoplanet_archive = NasaExoplanetArchive ()
213
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
223
214
224
215
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 ):
225
216
assert table == "ps"
@@ -235,9 +226,8 @@ def mock_run_query(table="ps", select='pl_name,ra,dec', coordinates=SkyCoord(ra=
235
226
236
227
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
237
228
Mock (side_effect = lambda x : 'https://some.url' ))
238
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
239
229
def test_query_criteria ():
240
- nasa_exoplanet_archive = NasaExoplanetArchive ()
230
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
241
231
242
232
def mock_run_query (table = "ps" , select = 'pl_name,discoverymethod,dec' , where = "discoverymethod like 'Microlensing' and dec > 0" ):
243
233
assert table == "ps"
@@ -255,9 +245,8 @@ def mock_run_query(table="ps", select='pl_name,discoverymethod,dec', where="disc
255
245
256
246
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
257
247
Mock (side_effect = lambda x : 'https://some.url' ))
258
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
259
248
def test_get_query_payload ():
260
- nasa_exoplanet_archive = NasaExoplanetArchive ()
249
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
261
250
262
251
def mock_run_query (table = "ps" , get_query_payload = True , select = "count(*)" , where = "disc_facility like '%TESS%'" ):
263
252
assert table == "ps"
@@ -276,9 +265,8 @@ def mock_run_query(table="ps", get_query_payload=True, select="count(*)", where=
276
265
277
266
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
278
267
Mock (side_effect = lambda x : 'https://some.url' ))
279
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
280
268
def test_select ():
281
- nasa_exoplanet_archive = NasaExoplanetArchive ()
269
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
282
270
283
271
def mock_run_query (table = "ps" , select = ["hostname" , "pl_name" ], where = "hostname='Kepler-11'" , get_query_payload = True ):
284
272
assert table == "ps"
@@ -295,9 +283,8 @@ def mock_run_query(table="ps", select=["hostname", "pl_name"], where="hostname='
295
283
296
284
@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
297
285
Mock (side_effect = lambda x : 'https://some.url' ))
298
- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
299
286
def test_get_tap_tables ():
300
- nasa_exoplanet_archive = NasaExoplanetArchive ()
287
+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
301
288
302
289
def mock_run_query (url = conf .url_tap ):
303
290
assert url == conf .url_tap
0 commit comments