Skip to content

Commit

Permalink
Warn when flat=True and curl_flag=True
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavies-st committed Sep 9, 2022
1 parent 9282366 commit 279c683
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions astroquery/mast/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ def _download_curl_script(self, products, out_dir):
"""

url_list = [("uri", url) for url in products['dataURI']]
download_file = "mastDownload_" + time.strftime("%Y%m%d%H%M%S")
local_path = os.path.join(out_dir.rstrip('/'), download_file + ".sh")
download_file = "mastDownload_" + time.strftime("%Y%m%d%H%M%S") + ".sh"
local_path = os.path.join(out_dir, download_file)

response = self._download_file(self._portal_api_connection.MAST_BUNDLE_URL + ".sh",
local_path, data=url_list, method="POST")
Expand Down Expand Up @@ -745,6 +745,9 @@ def download_products(self, products, *, download_dir=None, flat=False,
download_dir = '.'

if curl_flag: # don't want to download the files now, just the curl script
if flat:
# flat=True doesn't work with curl_flag=True, so issue a warning
warnings.warn("flat=True has no effect on curl downloads.", InputWarning)
manifest = self._download_curl_script(products,
download_dir)

Expand Down
15 changes: 14 additions & 1 deletion astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from astroquery import mast

from ..utils import ResolverError
from ...exceptions import (InvalidQueryError, MaxResultsWarning, NoResultsWarning,
from ...exceptions import (InputWarning, InvalidQueryError, MaxResultsWarning, NoResultsWarning,
RemoteServiceError)


Expand Down Expand Up @@ -318,6 +318,19 @@ def test_observations_download_products_flat(self, tmp_path, msa_product_table):

assert Path(manifest["Local Path"][0]).parent == tmp_path

def test_observations_download_products_flat_curl(self, tmp_path, msa_product_table):

# Get a product list with 6 duplicate JWST MSA config files
products = msa_product_table

assert len(products) == 6

# Download with flat=True, curl_flag=True, look for warning
with pytest.warns(InputWarning):
mast.Observations.download_products(products, flat=True,
curl_flag=True,
download_dir=tmp_path)

def test_observations_download_products_no_duplicates(self, tmp_path, caplog, msa_product_table):

# Get a product list with 6 duplicate JWST MSA config files
Expand Down

0 comments on commit 279c683

Please sign in to comment.