From 1b2aae72284b3f9e58084b5dda55e2605e89aaf6 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Mon, 22 Mar 2021 10:39:11 -0500 Subject: [PATCH] Add basic test for aux download script --- satpy/aux_download.py | 4 ++-- satpy/tests/test_data_download.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/satpy/aux_download.py b/satpy/aux_download.py index e6119407fc..a9f450a5fb 100644 --- a/satpy/aux_download.py +++ b/satpy/aux_download.py @@ -333,7 +333,7 @@ def _register_data_file(data_file_entry, comp_type): known_hash=known_hash) -def retrieve_all_cmd(): +def retrieve_all_cmd(argv=None): """Call 'retrieve_all' function from console script 'satpy_retrieve_all'.""" import argparse parser = argparse.ArgumentParser(description="Download auxiliary data files used by Satpy.") @@ -354,7 +354,7 @@ def retrieve_all_cmd(): help="Limit searching to these writers. If specified " "with no arguments, no writer files will be " "downloaded.") - args = parser.parse_args() + args = parser.parse_args(argv) logging.basicConfig(level=logging.INFO) diff --git a/satpy/tests/test_data_download.py b/satpy/tests/test_data_download.py index c16c939e14..15a45f1ec0 100644 --- a/satpy/tests/test_data_download.py +++ b/satpy/tests/test_data_download.py @@ -229,3 +229,20 @@ def test_no_downloads_in_tests(self): # offline downloading should still be allowed with satpy.config.set(download_aux=False): retrieve(cache_key) + + def test_download_script(self): + """Test basic functionality of the download script.""" + from satpy.aux_download import retrieve_all_cmd + import satpy + file_registry = {} + file_urls = {} + with satpy.config.set(config_path=[self.tmpdir]), \ + mock.patch('satpy.aux_download._FILE_REGISTRY', file_registry), \ + mock.patch('satpy.aux_download._FILE_URLS', file_urls), \ + mock.patch('satpy.aux_download.find_registerable_files'): + comp_file = 'composites/README.rst' + file_registry[comp_file] = None + file_urls[comp_file] = README_URL + assert not self.tmpdir.join(comp_file).exists() + retrieve_all_cmd(argv=["--data-dir", str(self.tmpdir)]) + assert self.tmpdir.join(comp_file).exists()