Skip to content

Commit f39fcf8

Browse files
authored
Merge pull request #2466 from mkelley/fix-mpc-error-messages-2022.07
Fix / test mpc error messages 2022.07
2 parents 7277870 + 6097b39 commit f39fcf8

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

astroquery/mpc/core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
from astropy.table import Table, QTable, Column
1212
import astropy.units as u
1313
from astropy.coordinates import EarthLocation, Angle, SkyCoord
14-
try:
15-
from astropy.utils.exceptions import ErfaWarning
16-
except ImportError:
17-
# DEPRECATED: remove eventually, but needed in July 2020
18-
from astropy._erfa.core import ErfaWarning
14+
from astropy.utils.exceptions import ErfaWarning
1915

2016
from ..query import BaseQuery
2117
from . import conf
2218
from ..utils import async_to_sync, class_or_instance
23-
from ..exceptions import InvalidQueryError
19+
from ..exceptions import InvalidQueryError, EmptyResponseError
2420

2521

2622
__all__ = ['MPCClass']
@@ -1183,8 +1179,12 @@ def _parse_result(self, result, **kwargs):
11831179
result.text))
11841180

11851181
if len(src) == 0:
1186-
raise RuntimeError(('No data queried. Are the target '
1187-
'identifiers correct?'))
1182+
raise EmptyResponseError(('No data queried. Are the target '
1183+
'identifiers correct? Is the MPC '
1184+
'database search working for your '
1185+
'object? The service is hosted at '
1186+
'https://www.minorplanetcenter.net/'
1187+
'search_db'))
11881188

11891189
# return raw response if requested
11901190
if self.get_raw_response:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2+
<html>
3+
<head>
4+
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
5+
<title>Minor Planet Ephemeris Service: Query Results</title>
6+
</head>
7+
<body>
8+
<h1>Minor Planet Ephemeris Service: Query Results</h1>
9+
Below are the results of your request from the Minor Planet Center's
10+
Minor Planet Ephemeris Service.
11+
Ephemerides are for
12+
the geocenter.
13+
<p><hr><p>
14+
No current elements found for 2008 JG. There may be published elements for this object; if there are, it is probably meaningless to make a current prediction of the basis of them. However, when this object is identified/recovered/rediscovered, elements will be available here. If the designation refers to a recently designated object, ephemerides will generally be available on the day following assignment of the designation.
15+
<p><hr><p>
16+
These calculations have been performed on the
17+
<a href="http://www.minorplanetcenter.net/iau/Ack/TamkinFoundation.html">Tamkin
18+
Foundation Computing Network</a>.
19+
<p><hr>
20+
<p>
21+
<a href="http://validator.w3.org/check?uri=referer"><img border="0"
22+
src="http://www.w3.org/Icons/valid-html401"
23+
alt="Valid HTML 4.01!" height="31" width="88"></a>
24+
</p>
25+
</body>
26+
</html>

astroquery/mpc/tests/test_mpc.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22
"""
33
test_mpc
44
5-
Generate offline ephemeris files for testing with the following
6-
commands. The asteroid must be one that returns ephemeris
7-
uncertainties:
5+
Generate offline ephemeris files for testing with the following commands.
6+
7+
* The first object can be any target with successful queries.
8+
9+
* The second object must be one that returns ephemeris uncertainties.
10+
11+
* The third object must be one that does not exist in the MPC database. The
12+
string 'test fail' is sufficient.
13+
14+
* The fourth object must be one that fails an orbit lookup. Today (2022
15+
July), that is 2008 JG, which has a permanent number 613986. The ephemeris
16+
service is not resolving the temporary designation to the permanent number,
17+
and therefore fails the orbit lookup.
18+
19+
Any changes to these queries (such as target name) must be reflected in the
20+
appropriate tests below.
821
922
```
1023
from astroquery.mpc import MPC
@@ -17,7 +30,8 @@
1730
'2P_ephemeris_500-a-s': ('2P', {'proper_motion': 'sky'}),
1831
'1994XG_ephemeris_500-a-t': ('1994 XG', {}),
1932
'1994XG_ephemeris_G37-a-t': ('1994 XG', {'location': 'G37'}),
20-
'testfail_ephemeris_500-a-t': ('test fail', {})
33+
'testfail_ephemeris_500-a-t': ('test fail', {}),
34+
'2008JG_ephemeris_500-a-t': ('2008 JG', {}),
2135
}
2236
for prefix, (name, kwargs) in parameters.items():
2337
with open(prefix + '.html', 'w') as outf:
@@ -39,7 +53,7 @@
3953
wget https://minorplanetcenter.net/iau/lists/ObsCodes.html
4054
4155
Then edit and remove all but the first 10 lines of observatories.
42-
This is sufficient for testing.
56+
This is sufficient for offline testing.
4357
4458
"""
4559
import os
@@ -180,6 +194,11 @@ def test_get_ephemeris_by_name_fail(patch_post):
180194
mpc.core.MPC.get_ephemeris('test fail')
181195

182196

197+
def test_get_ephemeris_object_without_orbit(patch_post):
198+
with pytest.raises(InvalidQueryError):
199+
mpc.core.MPC.get_ephemeris('2008 JG')
200+
201+
183202
def test_get_ephemeris_location_str():
184203
payload = mpc.core.MPC.get_ephemeris(
185204
'(1)', location='000', get_query_payload=True)

0 commit comments

Comments
 (0)