Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix esasky remote tests #2672

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 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()
Comment on lines +88 to +89
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I wonder whether this should rather be dealt with by a context manager somewhere in the module instead, but I suppose getting a workaround in the test would do for now.


@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,13 @@ 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 +147,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 +174,12 @@ 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 +198,15 @@ 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