Skip to content

Commit

Permalink
Fix esasky remote tests
Browse files Browse the repository at this point in the history
The two reasons the tests were failing were not using uppercase
filenames for file existence checks where needed and not closing
HDULists.
  • Loading branch information
eerovaher committed Feb 17, 2023
1 parent c293417 commit 8e9b2f0
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions astroquery/esasky/tests/test_esasky_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ def test_esasky_get_images_obs_id(self, tmp_path, mission, obsid):
result = ESASky.get_images(observation_ids=obsid,
missions=mission, download_dir=tmp_path)

assert Path(tmp_path, mission).exists()
assert Path(tmp_path, mission.upper()).exists()
if mission == "Herschel":
assert isinstance(result[mission.upper()][0]["250"], HDUList)
assert isinstance(result[mission.upper()][0]["350"], HDUList)
assert isinstance(result[mission.upper()][0]["500"], HDUList)
else:
assert isinstance(result[mission.upper()][0], HDUList)
for hdu_list in result[mission.upper()]:
hdu_list.close()

@pytest.mark.parametrize("mission, observation_id",
zip(["ISO-IR", "Chandra", "IUE", "XMM-NEWTON",
Expand All @@ -95,12 +97,13 @@ def test_esasky_get_spectra_obs_id(self, tmp_path, mission, observation_id):
result = ESASky.get_spectra(observation_ids=observation_id,
missions=mission, download_dir=tmp_path)

assert Path(tmp_path, mission).exists()
assert Path(tmp_path, mission.upper()).exists()
if mission == "Herschel":
assert isinstance(result[mission.upper()]["1342253595"]["WBS"]["WBS-V_USB_4b"], HDUList)
assert isinstance(result[mission.upper()]["1342253595"]["HRS"]["HRS-H_LSB_4b"], HDUList)
else:
assert isinstance(result[mission.upper()][0], HDUList)
result[mission.upper()][0].close()

def test_esasky_query_region_maps(self):
result = ESASky.query_region_maps(position="M51", radius="5 arcmin")
Expand All @@ -115,10 +118,15 @@ def test_esasky_query_object_maps(self):
'ISO-IR', 'Herschel', 'JWST-MID-IR',
'JWST-NEAR-IR', 'Spitzer'])
def test_esasky_get_images(self, tmp_path, mission):
ESASky.get_images(position="M51", missions=mission, download_dir=tmp_path)

result = ESASky.get_images(
position="M51", missions=mission, download_dir=tmp_path
)
assert tmp_path.stat().st_size

if mission != "Herschel" and result:
for hdu_list in result[mission.upper()]:
hdu_list.close()

@pytest.mark.bigdata
def test_esasky_get_images_hst(self, tmp_path):
ESASky.get_images(position="M11", radius="2.1 deg", missions="HST-UV",
Expand All @@ -141,12 +149,16 @@ def test_esasky_get_maps(self, tmp_path):
iso_maps = ESASky.query_object_maps(position="M51", missions=mission)
# Remove a few maps, so the other list will have downloadable ones, too
iso_maps[mission].remove_rows([0, 1])
ESASky.get_maps(iso_maps, download_dir=tmp_path)
result = ESASky.get_maps(iso_maps, download_dir=tmp_path)
assert len(os.listdir(file_path)) == len(all_maps[mission]) - 2
for hdu_list in result[mission]:
hdu_list.close()

iso_maps2 = dict({mission: all_maps[mission][:2]})
ESASky.get_maps(iso_maps2, download_dir=tmp_path)
result = ESASky.get_maps(iso_maps2, download_dir=tmp_path)
assert len(os.listdir(file_path)) == len(all_maps[mission])
for hdu_list in result[mission]:
hdu_list.close()

def test_esasky_query_region_spectra(self):
result = ESASky.query_region_spectra(position="M51", radius="5 arcmin")
Expand All @@ -164,9 +176,14 @@ def test_esasky_get_spectra(self, tmp_path, mission):
# - HST-IR, JWST-MID-IR and CHEOPS have no data
# - LAMOST does not support download
# - JWST-NEAR-IR returns a zip file with many fits files in it, unsupported
ESASky.get_spectra(position="M1", missions=mission, download_dir=tmp_path)
result = ESASky.get_spectra(
position="M1", missions=mission, download_dir=tmp_path
)
assert Path(tmp_path, mission.upper()).exists()

assert Path(tmp_path, mission).exists()
if mission != "Herschel":
for hdu_list in result[mission.upper()]:
hdu_list.close()

def test_esasky_get_spectra_small(self, tmp_path):
missions = ['HST-IR']
Expand All @@ -185,11 +202,19 @@ def test_esasky_get_spectra_from_table(self, tmp_path):
iso_spectra = ESASky.query_object_spectra(position="M51", missions=mission)
# Remove a few maps, so the other list will have downloadable ones, too
iso_spectra[mission].remove_rows([0, 1])
ESASky.get_spectra_from_table(query_table_list=iso_spectra, download_dir=tmp_path)
result = ESASky.get_spectra_from_table(
query_table_list=iso_spectra, download_dir=tmp_path
)
for hdu_list in result[mission]:
hdu_list.close()
assert len(os.listdir(file_path)) == len(all_spectra[mission]) - 2

iso_spectra2 = dict({mission: all_spectra[mission][:2]})
ESASky.get_spectra_from_table(query_table_list=iso_spectra2, download_dir=tmp_path)
result = ESASky.get_spectra_from_table(
query_table_list=iso_spectra2, download_dir=tmp_path
)
for hdu_list in result[mission]:
hdu_list.close()
assert len(os.listdir(file_path)) == len(all_spectra[mission])

def test_query(self):
Expand Down

0 comments on commit 8e9b2f0

Please sign in to comment.