Skip to content

Commit 5a88a03

Browse files
rickynilssonbsipocz
authored andcommitted
Fix tests.
1 parent ab1f117 commit 5a88a03

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

astroquery/ipac/nexsci/nasa_exoplanet_archive/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class Conf(_config.ConfigNamespace):
2121
url_tap = _config.ConfigItem(
2222
"https://exoplanetarchive.ipac.caltech.edu/TAP/",
2323
"URL for the NASA Exoplanet Archive TAP")
24+
url_aliaslookup = _config.ConfigItem(
25+
"https://exoplanetarchive.ipac.caltech.edu/cgi-bin/Lookup/nph-aliaslookup.py?objname=",
26+
"URL for the NASA Exoplanet Archive aliaslookup")
2427
timeout = _config.ConfigItem(
2528
600, "Time limit for requests from the NASA Exoplanet Archive servers")
2629
cache = _config.ConfigItem(False, "Should the requests be cached?")

astroquery/ipac/nexsci/nasa_exoplanet_archive/core.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def get_access_url(service='tap'):
107107
url = conf.url_tap
108108
elif service == 'api':
109109
url = conf.url_api
110+
elif service == 'aliaslookup':
111+
url = conf.url_aliaslookup
110112
return url
111113

112114

@@ -673,7 +675,7 @@ def _request_to_sql(self, request_payload):
673675
@deprecated(since="v0.4.1", alternative="query_object")
674676
@deprecated_renamed_argument(["show_progress", "table_path"],
675677
[None, None], "v0.4.1", arg_in_kwargs=True)
676-
def query_planet(self, planet_name, cache=None, regularize=True, **criteria):
678+
def query_planet(self, planet_name, cache=None, **criteria):
677679
"""
678680
Search the ``exoplanets`` table for a confirmed planet
679681
@@ -685,22 +687,18 @@ def query_planet(self, planet_name, cache=None, regularize=True, **criteria):
685687
cache : bool, optional
686688
Should the request result be cached? This can be useful for large repeated queries,
687689
but since the data in the archive is updated regularly, this defaults to ``False``.
688-
regularize : bool, optional
689-
If ``True``, the ``aliastable`` will be used to regularize the target name.
690690
**criteria
691691
Any other filtering criteria to apply. Values provided using the ``where`` keyword will
692692
be ignored.
693693
"""
694-
if regularize:
695-
planet_name = self._regularize_object_name(planet_name)
696694
criteria = self._handle_all_columns_argument(**criteria)
697695
criteria["where"] = "pl_name='{0}'".format(planet_name.strip())
698696
return self.query_criteria("exoplanets", cache=cache, **criteria)
699697

700698
@deprecated(since="v0.4.1", alternative="query_object")
701699
@deprecated_renamed_argument(["show_progress", "table_path"],
702700
[None, None], "v0.4.1", arg_in_kwargs=True)
703-
def query_star(self, host_name, cache=None, regularize=True, **criteria):
701+
def query_star(self, host_name, cache=None, **criteria):
704702
"""
705703
Search the ``exoplanets`` table for a confirmed planet host
706704
@@ -712,14 +710,10 @@ def query_star(self, host_name, cache=None, regularize=True, **criteria):
712710
cache : bool, optional
713711
Should the request result be cached? This can be useful for large repeated queries,
714712
but since the data in the archive is updated regularly, this defaults to ``False``.
715-
regularize : bool, optional
716-
If ``True``, the ``aliastable`` will be used to regularize the target name.
717713
**criteria
718714
Any other filtering criteria to apply. Values provided using the ``where`` keyword will
719715
be ignored.
720716
"""
721-
if regularize:
722-
host_name = self._regularize_object_name(host_name)
723717
criteria = self._handle_all_columns_argument(**criteria)
724718
criteria["where"] = "pl_hostname='{0}'".format(host_name.strip())
725719
return self.query_criteria("exoplanets", cache=cache, **criteria)

astroquery/ipac/nexsci/nasa_exoplanet_archive/tests/test_nasa_exoplanet_archive.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666

6767

6868
def mock_get(self, method, url, *args, **kwargs): # pragma: nocover
69-
if method!='test_regularize_object_name':
70-
assert url == conf.url_api
69+
assert url == conf.url_api
7170

7271
params = kwargs.get("params", None)
7372
assert params is not None
@@ -120,16 +119,16 @@ def patch_get(request): # pragma: nocover
120119
return mp
121120

122121

123-
def test_regularize_object_name(patch_get):
124-
NasaExoplanetArchiveMock = NasaExoplanetArchiveClass()
122+
# def test_regularize_object_name(patch_get):
123+
# NasaExoplanetArchiveMock = NasaExoplanetArchiveClass()
125124

126-
NasaExoplanetArchiveMock._tap_tables = ['list']
127-
assert NasaExoplanetArchiveMock._regularize_object_name("kepler 2") == "HAT-P-7"
128-
assert NasaExoplanetArchiveMock._regularize_object_name("kepler 1 b") == "TrES-2 b"
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"
129128

130-
with pytest.warns(NoResultsWarning) as warning:
131-
NasaExoplanetArchiveMock._regularize_object_name("not a planet")
132-
assert "No aliases found for name: 'not a planet'" == str(warning[0].message)
129+
# with pytest.warns(NoResultsWarning) as warning:
130+
# NasaExoplanetArchiveMock._regularize_object_name("not a planet")
131+
# assert "No aliases found for name: 'not a planet'" == str(warning[0].message)
133132

134133

135134
def test_backwards_compat(patch_get):
@@ -298,6 +297,25 @@ def mock_run_query(url=conf.url_tap):
298297
assert 'pscomppars' in result
299298

300299

300+
@patch('astroquery.ipac.nexsci.nasa_exoplanet_archive.core.get_access_url',
301+
Mock(side_effect=lambda x: 'https://some.url'))
302+
def test_query_aliases():
303+
nasa_exoplanet_archive = NasaExoplanetArchiveClass()
304+
305+
def mock_run_query(url=conf.url_aliaslookup, object_name="HD 209458"):
306+
assert url == conf.url_aliaslookup
307+
assert object_name == "HD 209458"
308+
result = PropertyMock()
309+
result = ['HD 209458', '2MASS J22031077+1853036', 'BD+18 4917', 'Gaia DR2 1779546757669063552',\
310+
'HIP 108859', 'SAO 107623', 'TIC 420814525', 'TYC 1688-01821-1', 'V0376 Peg', 'WISE J220310.79+185303.3']
311+
return result
312+
nasa_exoplanet_archive.query_aliases = mock_run_query
313+
result = nasa_exoplanet_archive.query_aliases()
314+
assert 'HD 209458' in result
315+
assert 'HIP 108859' in result
316+
assert 'V0376 Peg' in result
317+
318+
301319
def test_deprecated_namespace_import_warning():
302320
with pytest.warns(DeprecationWarning):
303321
import astroquery.nasa_exoplanet_archive

0 commit comments

Comments
 (0)