Skip to content

Commit

Permalink
Merge pull request #2466 from mkelley/fix-mpc-error-messages-2022.07
Browse files Browse the repository at this point in the history
Fix / test mpc error messages 2022.07
  • Loading branch information
bsipocz authored May 9, 2023
2 parents 7277870 + 6097b39 commit f39fcf8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
16 changes: 8 additions & 8 deletions astroquery/mpc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
from astropy.table import Table, QTable, Column
import astropy.units as u
from astropy.coordinates import EarthLocation, Angle, SkyCoord
try:
from astropy.utils.exceptions import ErfaWarning
except ImportError:
# DEPRECATED: remove eventually, but needed in July 2020
from astropy._erfa.core import ErfaWarning
from astropy.utils.exceptions import ErfaWarning

from ..query import BaseQuery
from . import conf
from ..utils import async_to_sync, class_or_instance
from ..exceptions import InvalidQueryError
from ..exceptions import InvalidQueryError, EmptyResponseError


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

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

# return raw response if requested
if self.get_raw_response:
Expand Down
26 changes: 26 additions & 0 deletions astroquery/mpc/tests/data/2008JG_ephemeris_500-a-t.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Minor Planet Ephemeris Service: Query Results</title>
</head>
<body>
<h1>Minor Planet Ephemeris Service: Query Results</h1>
Below are the results of your request from the Minor Planet Center's
Minor Planet Ephemeris Service.
Ephemerides are for
the geocenter.
<p><hr><p>
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.
<p><hr><p>
These calculations have been performed on the
<a href="http://www.minorplanetcenter.net/iau/Ack/TamkinFoundation.html">Tamkin
Foundation Computing Network</a>.
<p><hr>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img border="0"
src="http://www.w3.org/Icons/valid-html401"
alt="Valid HTML 4.01!" height="31" width="88"></a>
</p>
</body>
</html>
29 changes: 24 additions & 5 deletions astroquery/mpc/tests/test_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
"""
test_mpc
Generate offline ephemeris files for testing with the following
commands. The asteroid must be one that returns ephemeris
uncertainties:
Generate offline ephemeris files for testing with the following commands.
* The first object can be any target with successful queries.
* The second object must be one that returns ephemeris uncertainties.
* The third object must be one that does not exist in the MPC database. The
string 'test fail' is sufficient.
* The fourth object must be one that fails an orbit lookup. Today (2022
July), that is 2008 JG, which has a permanent number 613986. The ephemeris
service is not resolving the temporary designation to the permanent number,
and therefore fails the orbit lookup.
Any changes to these queries (such as target name) must be reflected in the
appropriate tests below.
```
from astroquery.mpc import MPC
Expand All @@ -17,7 +30,8 @@
'2P_ephemeris_500-a-s': ('2P', {'proper_motion': 'sky'}),
'1994XG_ephemeris_500-a-t': ('1994 XG', {}),
'1994XG_ephemeris_G37-a-t': ('1994 XG', {'location': 'G37'}),
'testfail_ephemeris_500-a-t': ('test fail', {})
'testfail_ephemeris_500-a-t': ('test fail', {}),
'2008JG_ephemeris_500-a-t': ('2008 JG', {}),
}
for prefix, (name, kwargs) in parameters.items():
with open(prefix + '.html', 'w') as outf:
Expand All @@ -39,7 +53,7 @@
wget https://minorplanetcenter.net/iau/lists/ObsCodes.html
Then edit and remove all but the first 10 lines of observatories.
This is sufficient for testing.
This is sufficient for offline testing.
"""
import os
Expand Down Expand Up @@ -180,6 +194,11 @@ def test_get_ephemeris_by_name_fail(patch_post):
mpc.core.MPC.get_ephemeris('test fail')


def test_get_ephemeris_object_without_orbit(patch_post):
with pytest.raises(InvalidQueryError):
mpc.core.MPC.get_ephemeris('2008 JG')


def test_get_ephemeris_location_str():
payload = mpc.core.MPC.get_ephemeris(
'(1)', location='000', get_query_payload=True)
Expand Down

0 comments on commit f39fcf8

Please sign in to comment.