Skip to content

Commit 1dbe04f

Browse files
Clara Brasseurjaymedina
authored andcommitted
adding a few more tests for error conditions. also making code style fixes.
1 parent 8b0dbd5 commit 1dbe04f

File tree

4 files changed

+56
-30
lines changed

4 files changed

+56
-30
lines changed

astroquery/mast/cutouts.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
133133
or TIC ID (objectname="TIC 141914082").
134134
One and only one of coordinates, objectname, moving_target must be supplied.
135135
moving_target : str, optional
136-
The name or ID (as understood by the
137-
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
136+
The name or ID (as understood by the
137+
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
138138
of a moving target such as an asteroid or comet.
139139
One and only one of coordinates, objectname, and moving_target must be supplied.
140140
mt_type : str, optional
@@ -150,7 +150,7 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
150150

151151
if moving_target:
152152

153-
# Check only ony object designator has been passed in
153+
# Check only ony object designator has been passed in
154154
if objectname or coordinates:
155155
raise InvalidQueryError("Only one of objectname, coordinates, and moving_target may be specified.")
156156

@@ -163,7 +163,7 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
163163
response = self._service_api_connection.service_request_async("mt_sector", params)
164164

165165
else:
166-
166+
167167
# Get Skycoord object for coordinates/object
168168
coordinates = parse_input_location(coordinates, objectname)
169169

@@ -176,8 +176,8 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
176176

177177
response = self._service_api_connection.service_request_async("sector", params)
178178

179-
# Raise any errors
180-
response.raise_for_status()
179+
# Raise any errors
180+
response.raise_for_status()
181181

182182
sector_json = response.json()['results']
183183
sector_dict = {'sectorName': [],
@@ -232,8 +232,8 @@ def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", infl
232232
or TIC ID (objectname="TIC 141914082").
233233
One and only one of coordinates, objectname, and moving_target must be supplied.
234234
moving_target : str, optional
235-
The name or ID (as understood by the
236-
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
235+
The name or ID (as understood by the
236+
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
237237
of a moving target such as an asteroid or comet.
238238
One and only one of coordinates, objectname, and moving_target must be supplied.
239239
mt_type : str, optional
@@ -247,23 +247,23 @@ def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", infl
247247
"""
248248

249249
if moving_target:
250-
# Check only ony object designator has been passed in
250+
# Check only ony object designator has been passed in
251251
if objectname or coordinates:
252252
raise InvalidQueryError("Only one of objectname, coordinates, and moving_target may be specified.")
253-
253+
254254
astrocut_request = f"moving_target/astrocut?obj_id={moving_target}"
255255
if mt_type:
256256
astrocut_request += f"&obj_type={mt_type}"
257257
else:
258258
# Get Skycoord object for coordinates/object
259259
coordinates = parse_input_location(coordinates, objectname)
260-
260+
261261
astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}"
262262

263263
# Adding the arguments that are common between moving/still astrocut requests
264264
size_dict = _parse_cutout_size(size)
265265
astrocut_request += f"&y={size_dict['y']}&x={size_dict['x']}&units={size_dict['units']}"
266-
266+
267267
if sector:
268268
astrocut_request += "&sector={}".format(sector)
269269

@@ -325,8 +325,8 @@ def get_cutouts(self, coordinates=None, size=5, sector=None,
325325
or TIC ID (objectname="TIC 141914082").
326326
One and only one of coordinates, objectname, and moving_target must be supplied.
327327
moving_target : str, optional
328-
The name or ID (as understood by the
329-
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
328+
The name or ID (as understood by the
329+
`JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
330330
of a moving target such as an asteroid or comet.
331331
One and only one of coordinates, objectname, and moving_target must be supplied.
332332
mt_type : str, optional
@@ -345,10 +345,10 @@ def get_cutouts(self, coordinates=None, size=5, sector=None,
345345
# Add sector if present
346346
if sector:
347347
param_dict["sector"] = sector
348-
348+
349349
if moving_target:
350350

351-
# Check only on object designator has been passed in
351+
# Check only on object designator has been passed in
352352
if objectname or coordinates:
353353
raise InvalidQueryError("Only one of objectname, coordinates, and moving_target may be specified.")
354354

@@ -361,13 +361,13 @@ def get_cutouts(self, coordinates=None, size=5, sector=None,
361361
response = self._service_api_connection.service_request_async("mt_astrocut", param_dict)
362362

363363
else:
364-
364+
365365
# Get Skycoord object for coordinates/object
366366
coordinates = parse_input_location(coordinates, objectname)
367-
367+
368368
param_dict["ra"] = coordinates.ra.deg
369369
param_dict["dec"] = coordinates.dec.deg
370-
370+
371371
response = self._service_api_connection.service_request_async("astrocut", param_dict)
372372

373373
response.raise_for_status() # Raise any errors

astroquery/mast/observations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ def download_file(self, uri, local_path=None, base_url=None, cache=True, cloud_o
572572
self._download_file(data_url, local_path,
573573
cache=cache, head_safe=True, continuation=False)
574574
else:
575-
575+
576576
self._download_file(data_url, local_path,
577577
cache=cache, head_safe=True, continuation=False)
578578

astroquery/mast/tests/test_mast.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import astropy.units as u
1414

1515
from ...utils.testing_tools import MockResponse
16-
from ...exceptions import (InvalidQueryError, InputWarning)
16+
from ...exceptions import InvalidQueryError, InputWarning
1717

1818
from ... import mast
1919

@@ -598,6 +598,17 @@ def test_tesscut_get_sector(patch_post):
598598
assert sector_table['camera'][0] == 1
599599
assert sector_table['ccd'][0] == 3
600600

601+
# Testing catch for multiple designators'
602+
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
603+
604+
with pytest.raises(InvalidQueryError) as invalid_query:
605+
mast.Tesscut.get_sectors(moving_target="Ceres", coordinates=coord)
606+
assert error_str in str(invalid_query.value)
607+
608+
with pytest.raises(InvalidQueryError) as invalid_query:
609+
mast.Tesscut.get_sectors(moving_target="Ceres", objectname="M103")
610+
assert error_str in str(invalid_query.value)
611+
601612

602613
def test_tesscut_download_cutouts(patch_post, tmpdir):
603614

@@ -632,6 +643,17 @@ def test_tesscut_download_cutouts(patch_post, tmpdir):
632643
assert manifest["Local Path"][0][-4:] == "fits"
633644
assert os.path.isfile(manifest[0]['Local Path'])
634645

646+
# Testing catch for multiple designators'
647+
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
648+
649+
with pytest.raises(InvalidQueryError) as invalid_query:
650+
mast.Tesscut.download_cutouts(moving_target="Eleonora", coordinates=coord, size=5, path=str(tmpdir))
651+
assert error_str in str(invalid_query.value)
652+
653+
with pytest.raises(InvalidQueryError) as invalid_query:
654+
mast.Tesscut.download_cutouts(moving_target="Eleonora", objectname="M103", size=5, path=str(tmpdir))
655+
assert error_str in str(invalid_query.value)
656+
635657

636658
def test_tesscut_get_cutouts(patch_post, tmpdir):
637659

@@ -653,6 +675,17 @@ def test_tesscut_get_cutouts(patch_post, tmpdir):
653675
assert len(cutout_hdus_list) == 1
654676
assert isinstance(cutout_hdus_list[0], fits.HDUList)
655677

678+
# Testing catch for multiple designators'
679+
error_str = "Only one of objectname, coordinates, and moving_target may be specified."
680+
681+
with pytest.raises(InvalidQueryError) as invalid_query:
682+
mast.Tesscut.get_cutouts(moving_target="Eleonora", coordinates=coord, size=5)
683+
assert error_str in str(invalid_query.value)
684+
685+
with pytest.raises(InvalidQueryError) as invalid_query:
686+
mast.Tesscut.get_cutouts(moving_target="Eleonora", objectname="M103", size=5)
687+
assert error_str in str(invalid_query.value)
688+
656689

657690
######################
658691
# ZcutClass tests #

astroquery/mast/tests/test_mast_remote.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def test_observations_query_criteria_count(self):
197197

198198
# product functions
199199
def test_observations_get_product_list_async(self):
200-
201-
test_obs = mast.Observations.query_criteria(filters=["NUV","FUV"],objectname="M101")
200+
201+
test_obs = mast.Observations.query_criteria(filters=["NUV", "FUV"], objectname="M101")
202202

203203
responses = mast.Observations.get_product_list_async(test_obs[0]["obsid"])
204204
assert isinstance(responses, list)
@@ -247,12 +247,8 @@ def test_observations_get_product_list(self):
247247
result = mast.Observations.get_product_list(observations[obsLocs])
248248
obs_collection = np.unique(list(result['obs_collection']))
249249
assert isinstance(result, Table)
250-
<<<<<<< HEAD
251250
assert len(obs_collection) == 1
252251
assert obs_collection[0] == 'IUE'
253-
=======
254-
assert len(result) > 10
255-
>>>>>>> adding moving tesscut tests
256252

257253
def test_observations_filter_products(self):
258254
observations = mast.Observations.query_object("M8", radius=".04 deg")
@@ -714,7 +710,6 @@ def test_tesscut_get_sectors(self):
714710
assert sector_table['camera'][0] == 1
715711
assert sector_table['ccd'][0] == 1
716712

717-
718713
def test_tesscut_download_cutouts(self, tmpdir):
719714

720715
coord = SkyCoord(349.62609, -47.12424, unit="deg")
@@ -760,7 +755,6 @@ def test_tesscut_download_cutouts(self, tmpdir):
760755
assert manifest["Local Path"][0][-4:] == "fits"
761756
for row in manifest:
762757
assert os.path.isfile(row['Local Path'])
763-
764758

765759
def test_tesscut_get_cutouts(self, tmpdir):
766760

@@ -793,7 +787,6 @@ def test_tesscut_get_cutouts(self, tmpdir):
793787
assert len(cutout_hdus_list) == 1
794788
assert isinstance(cutout_hdus_list[0], fits.HDUList)
795789

796-
797790
###################
798791
# ZcutClass tests #
799792
###################

0 commit comments

Comments
 (0)