Skip to content

Commit c1d15f5

Browse files
Raul Gutierrezbsipocz
authored andcommitted
New unit tests to cover new filters.
1 parent ab85253 commit c1d15f5

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

astroquery/jwst/core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,7 @@ def __get_callevel_condition(self, cal_level):
883883
condition = " AND calibrationlevel="+\
884884
str(cal_level)+" "
885885
else:
886-
raise ValueError("cal_level must be either 'Top' or \
887-
an integer. ")
886+
raise ValueError("cal_level must be either 'Top' or an integer")
888887
return condition
889888

890889
def __get_public_condition(self, only_public):
@@ -895,16 +894,16 @@ def __get_public_condition(self, only_public):
895894
condition = " AND public='true' "
896895
return condition
897896

898-
def __get_plane_dataproducttype_condition(self, dataproduct_type=None):
897+
def __get_plane_dataproducttype_condition(self, prod_type=None):
899898
condition = ""
900-
if(dataproduct_type is not None):
901-
if(not isinstance(dataproduct_type, str)):
902-
raise ValueError("dataproduct_type must be string")
903-
elif(str(dataproduct_type).lower() not in self.PLANE_DATAPRODUCT_TYPES):
904-
raise ValueError("dataproduct_type must be one of: " +\
899+
if(prod_type is not None):
900+
if(not isinstance(prod_type, str)):
901+
raise ValueError("prod_type must be string")
902+
elif(str(prod_type).lower() not in self.PLANE_DATAPRODUCT_TYPES):
903+
raise ValueError("prod_type must be one of: " +\
905904
str(', '.join(self.PLANE_DATAPRODUCT_TYPES)))
906905
else:
907-
condition = " AND dataproducttype LIKE '"+dataproduct_type.lower()+"' "
906+
condition = " AND dataproducttype LIKE '"+prod_type.lower()+"' "
908907
return condition
909908

910909
def __get_instrument_name_condition(self, value=None):

astroquery/jwst/tests/test_jwsttap.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,54 @@ def test_query_region(self):
197197
sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree), frame='icrs')
198198
with pytest.raises(ValueError) as err:
199199
tap.query_region(sc)
200+
print(err.value.args[0])
200201
assert "Missing required argument: 'width'" in err.value.args[0]
201202

202203
width = Quantity(12, u.deg)
204+
height = Quantity(10, u.deg)
203205

204206
with pytest.raises(ValueError) as err:
205207
tap.query_region(sc, width=width)
206208
assert "Missing required argument: 'height'" in err.value.args[0]
207209

208-
height = Quantity(10, u.deg)
210+
#Test cal_level argument
211+
with pytest.raises(ValueError) as err:
212+
tap.query_region(sc, width=width, height=height, cal_level='a')
213+
assert "cal_level must be either 'Top' or an integer" in err.value.args[0]
214+
215+
#Test only_public
216+
with pytest.raises(ValueError) as err:
217+
tap.query_region(sc, width=width, height=height, only_public='a')
218+
assert "only_public must be boolean" in err.value.args[0]
219+
220+
#Test dataproduct_type argument
221+
with pytest.raises(ValueError) as err:
222+
tap.query_region(sc, width=width, height=height, prod_type=1)
223+
assert "prod_type must be string" in err.value.args[0]
224+
225+
with pytest.raises(ValueError) as err:
226+
tap.query_region(sc, width=width, height=height, prod_type='a')
227+
assert "prod_type must be one of: " in err.value.args[0]
228+
229+
#Test instrument_name argument
230+
with pytest.raises(ValueError) as err:
231+
tap.query_region(sc, width=width, height=height, instrument_name=1)
232+
assert "instrument_name must be string" in err.value.args[0]
233+
234+
with pytest.raises(ValueError) as err:
235+
tap.query_region(sc, width=width, height=height, instrument_name='a')
236+
assert "instrument_name must be one of: " in err.value.args[0]
237+
238+
#Test filter_name argument
239+
with pytest.raises(ValueError) as err:
240+
tap.query_region(sc, width=width, height=height, filter_name=1)
241+
assert "filter_name must be string" in err.value.args[0]
242+
243+
#Test proposal_id argument
244+
with pytest.raises(ValueError) as err:
245+
tap.query_region(sc, width=width, height=height, proposal_id='a')
246+
assert "proposal_id must be an integer" in err.value.args[0]
247+
209248
table = tap.query_region(sc, width=width, height=height)
210249
assert len(table) == 3, \
211250
"Wrong job results (num rows). Expected: %d, found %d" % \
@@ -403,6 +442,45 @@ def test_cone_search_sync(self):
403442
None,
404443
np.int32)
405444

445+
#Test cal_level argument
446+
with pytest.raises(ValueError) as err:
447+
tap.cone_search(sc, radius, cal_level='a')
448+
assert "cal_level must be either 'Top' or an integer" in err.value.args[0]
449+
450+
#Test only_public
451+
with pytest.raises(ValueError) as err:
452+
tap.cone_search(sc, radius, only_public='a')
453+
assert "only_public must be boolean" in err.value.args[0]
454+
455+
#Test dataproduct_type argument
456+
with pytest.raises(ValueError) as err:
457+
tap.cone_search(sc, radius, prod_type=1)
458+
assert "prod_type must be string" in err.value.args[0]
459+
460+
with pytest.raises(ValueError) as err:
461+
tap.cone_search(sc, radius, prod_type='a')
462+
assert "prod_type must be one of: " in err.value.args[0]
463+
464+
#Test instrument_name argument
465+
with pytest.raises(ValueError) as err:
466+
tap.cone_search(sc, radius, instrument_name=1)
467+
assert "instrument_name must be string" in err.value.args[0]
468+
469+
with pytest.raises(ValueError) as err:
470+
tap.cone_search(sc, radius, instrument_name='a')
471+
assert "instrument_name must be one of: " in err.value.args[0]
472+
473+
#Test filter_name argument
474+
with pytest.raises(ValueError) as err:
475+
tap.cone_search(sc, radius, filter_name=1)
476+
assert "filter_name must be string" in err.value.args[0]
477+
478+
#Test proposal_id argument
479+
with pytest.raises(ValueError) as err:
480+
tap.cone_search(sc, radius, proposal_id='a')
481+
assert "proposal_id must be an integer" in err.value.args[0]
482+
483+
406484
def test_cone_search_async(self):
407485
connHandler = DummyConnHandler()
408486
tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)

0 commit comments

Comments
 (0)