11# Licensed under a 3-clause BSD style license - see LICENSE.rst
2-
3-
42import json
53import os
64import sys
75from urllib .parse import urlencode
86
97import 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
148import pkg_resources
159import pytest
1610import 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+
2312from astropy .coordinates import SkyCoord
24- from astropy .tests .helper import assert_quantity_allclose
2513from astropy .utils .exceptions import AstropyDeprecationWarning
2614
27- from ...exceptions import InputWarning , InvalidQueryError , NoResultsWarning
15+ from ...exceptions import NoResultsWarning
2816from ...utils .testing_tools import MockResponse
29- from ..core import NasaExoplanetArchive , conf , InvalidTableError
17+ from ..core import NasaExoplanetArchiveClass , conf , InvalidTableError
3018try :
3119 from unittest .mock import Mock , patch , PropertyMock
3220except ImportError :
@@ -132,12 +120,14 @@ def patch_get(request): # pragma: nocover
132120
133121
134122def 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"
138128
139129 with pytest .warns (NoResultsWarning ) as warning :
140- NasaExoplanetArchive ._regularize_object_name ("not a planet" )
130+ NasaExoplanetArchiveMock ._regularize_object_name ("not a planet" )
141131 assert "No aliases found for name: 'not a planet'" == str (warning [0 ].message )
142132
143133
@@ -146,44 +136,47 @@ def test_backwards_compat(patch_get):
146136 These are the tests from the previous version of this interface.
147137 They query old tables by default and should return InvalidTableError.
148138 """
149- NasaExoplanetArchive ._tap_tables = ['list' ]
139+ NasaExoplanetArchiveMock = NasaExoplanetArchiveClass ()
140+
141+ NasaExoplanetArchiveMock ._tap_tables = ['list' ]
150142
151143 # test_hd209458b_exoplanets_archive
152144 with pytest .warns (AstropyDeprecationWarning ):
153145 with pytest .raises (InvalidTableError ) as error :
154- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
146+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
155147 assert "replaced" in str (error )
156148
157149 # test_hd209458b_exoplanet_archive_coords
158150 with pytest .warns (AstropyDeprecationWarning ):
159151 with pytest .raises (InvalidTableError ) as error :
160- params = NasaExoplanetArchive .query_planet ("HD 209458 b " )
152+ NasaExoplanetArchiveMock .query_planet ("HD 209458 b " )
161153 assert "replaced" in str (error )
162154
163155 # test_hd209458_stellar_exoplanet
164156 with pytest .warns (AstropyDeprecationWarning ):
165157 with pytest .raises (InvalidTableError ) as error :
166- params = NasaExoplanetArchive .query_star ("HD 209458" )
158+ NasaExoplanetArchiveMock .query_star ("HD 209458" )
167159 assert "replaced" in str (error )
168160
169161 # test_hd136352_stellar_exoplanet_archive
170162 with pytest .warns (AstropyDeprecationWarning ):
171163 with pytest .raises (InvalidTableError ) as error :
172- params = NasaExoplanetArchive .query_star ("HD 136352" )
164+ NasaExoplanetArchiveMock .query_star ("HD 136352" )
173165 assert "replaced" in str (error )
174166
175167 # test_exoplanet_archive_query_all_columns
176168 with pytest .warns (AstropyDeprecationWarning ):
177169 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 )
179171 assert "replaced" in str (error )
180172
181173
182- @pytest .mark .filterwarnings ("error" )
183174@pytest .mark .parametrize ("table,query" , API_TABLES )
184175def 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 )
187180 assert len (data ) > 0
188181
189182 # Check that the units were fixed properly
@@ -194,9 +187,8 @@ def test_api_tables(patch_get, table, query):
194187# Mock tests on TAP service below
195188@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
196189 Mock (side_effect = lambda x : 'https://some.url' ))
197- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
198190def test_query_object ():
199- nasa_exoplanet_archive = NasaExoplanetArchive ()
191+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
200192
201193 def mock_run_query (object_name = "K2-18 b" , table = "pscomppars" , select = "pl_name,disc_year,discoverymethod,ra,dec" ):
202194 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
217209
218210@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
219211 Mock (side_effect = lambda x : 'https://some.url' ))
220- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
221212def test_query_region ():
222- nasa_exoplanet_archive = NasaExoplanetArchive ()
213+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
223214
224215 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 ):
225216 assert table == "ps"
@@ -235,9 +226,8 @@ def mock_run_query(table="ps", select='pl_name,ra,dec', coordinates=SkyCoord(ra=
235226
236227@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
237228 Mock (side_effect = lambda x : 'https://some.url' ))
238- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
239229def test_query_criteria ():
240- nasa_exoplanet_archive = NasaExoplanetArchive ()
230+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
241231
242232 def mock_run_query (table = "ps" , select = 'pl_name,discoverymethod,dec' , where = "discoverymethod like 'Microlensing' and dec > 0" ):
243233 assert table == "ps"
@@ -255,9 +245,8 @@ def mock_run_query(table="ps", select='pl_name,discoverymethod,dec', where="disc
255245
256246@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
257247 Mock (side_effect = lambda x : 'https://some.url' ))
258- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
259248def test_get_query_payload ():
260- nasa_exoplanet_archive = NasaExoplanetArchive ()
249+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
261250
262251 def mock_run_query (table = "ps" , get_query_payload = True , select = "count(*)" , where = "disc_facility like '%TESS%'" ):
263252 assert table == "ps"
@@ -276,9 +265,8 @@ def mock_run_query(table="ps", get_query_payload=True, select="count(*)", where=
276265
277266@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
278267 Mock (side_effect = lambda x : 'https://some.url' ))
279- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
280268def test_select ():
281- nasa_exoplanet_archive = NasaExoplanetArchive ()
269+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
282270
283271 def mock_run_query (table = "ps" , select = ["hostname" , "pl_name" ], where = "hostname='Kepler-11'" , get_query_payload = True ):
284272 assert table == "ps"
@@ -295,9 +283,8 @@ def mock_run_query(table="ps", select=["hostname", "pl_name"], where="hostname='
295283
296284@patch ('astroquery.nasa_exoplanet_archive.core.get_access_url' ,
297285 Mock (side_effect = lambda x : 'https://some.url' ))
298- @pytest .mark .skipif (not pyvo_OK , reason = 'not pyvo_OK' )
299286def test_get_tap_tables ():
300- nasa_exoplanet_archive = NasaExoplanetArchive ()
287+ nasa_exoplanet_archive = NasaExoplanetArchiveClass ()
301288
302289 def mock_run_query (url = conf .url_tap ):
303290 assert url == conf .url_tap
0 commit comments