Skip to content

Commit

Permalink
Add test for flat MAST downloads; consolidate test setup in fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Sep 8, 2022
1 parent 521f829 commit 4933462
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from re import sub
import numpy as np
import os
import pytest
Expand All @@ -21,6 +22,19 @@
OBSID = '1647157'


@pytest.fixture(scope="module")
def msa_product_table():
# Pull products for a JWST NIRSpec MSA observation with 6 known
# duplicates of the MSA configuration file, propID=2736
products = mast.Observations.get_product_list("87602009")

# Filter out everything but the MSA config file
mask = np.char.find(products["dataURI"], "_msa.fits") != -1
products = products[mask]

return products


@pytest.mark.remote_data
class TestMast:

Expand Down Expand Up @@ -290,26 +304,37 @@ def test_observations_download_products(self, tmpdir):
assert os.path.isfile(result2['Local Path'][0])
assert len(result2) == 1

def test_observations_download_products_no_duplicates(tmpdir):
def test_observations_download_products_flat(self, msa_product_table, tmp_path):

products = msa_product_table

# Pull products for a JWST NIRSpec MSA observation with 6 known
# duplicates of the MSA configuration file, propID=2736
products = mast.Observations.get_product_list("87602009")
# Download with flat=True
with pytest.warns(None):
manifest = mast.Observations.download_products(products, flat=True,
download_dir=tmp_path)

# Filter out everything but the MSA config file
mask = np.char.find(products["dataURI"], "_msa.fits") != -1
products = products[mask]
downloaded_path = manifest["Local Path"][0]
filename = os.path.basename(downloaded_path)
assert downloaded_path == (tmp_path / filename).as_posix()

def test_observations_download_products_no_duplicates(self, msa_product_table, tmp_path):

products = msa_product_table

assert len(products) == 6

# Download the product
with pytest.warns(DuplicateResultsWarning):
manifest = mast.Observations.download_products(products,
download_dir=str(tmpdir))
download_dir=tmp_path)

# Check that it downloads the MSA config file only once
assert len(manifest) == 1

def test_observations_get_cloud_uris_no_duplicates(self, msa_product_table):

products = msa_product_table

# enable access to public AWS S3 bucket
mast.Observations.enable_cloud_dataset()

Expand All @@ -319,7 +344,7 @@ def test_observations_download_products_no_duplicates(tmpdir):

assert len(uris) == 1

def test_observations_download_file(self, tmpdir):
def test_observations_download_file(self):

# enabling cloud connection
mast.Observations.enable_cloud_dataset(provider='AWS')
Expand Down

0 comments on commit 4933462

Please sign in to comment.