-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 handle errors from non http url sources (#61)
* generic error hadnling * generic error hadnling * #60 * #60 * backup downloader added * add tests for ftp * fix urls * fix test * cleanup * wget only * ftp test added * multiurl updated to handle ftp properly * qa * unit tests * qa * removing unused test * clean up and extra download test * qa * Mattia comments addressed --------- Co-authored-by: Mattia Almansi <m.almansi@bopen.eu>
- Loading branch information
Showing
5 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ dependencies: | |
- cfgrib | ||
- h5netcdf | ||
- wget | ||
- multiurl>=0.2.3.2 | ||
- pyyaml | ||
- pip: | ||
- rooki | ||
- multiurl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from cads_adaptors.tools import url_tools | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"urls,expected_nfiles", | ||
( | ||
( | ||
[ | ||
"https://get.ecmwf.int/repository/test-data/earthkit-data/test-data/test_single.nc" | ||
], | ||
1, | ||
), | ||
( | ||
[ | ||
"https://get.ecmwf.int/repository/test-data/earthkit-data/test-data/test_single.nc", | ||
"https://get.ecmwf.int/repository/test-data/earthkit-data/test-data/test_single.grib", | ||
], | ||
2, | ||
), | ||
), | ||
) | ||
def test_downloaders(tmp_path, monkeypatch, urls, expected_nfiles): | ||
monkeypatch.chdir(tmp_path) # try_download generates files in the working dir | ||
paths = url_tools.try_download(urls) | ||
assert len(paths) == expected_nfiles | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"anon", | ||
( | ||
True, | ||
False, | ||
), | ||
) | ||
def test_ftp_download(tmp_path, ftpserver, anon): | ||
local_test_file = os.path.join(tmp_path, "testfile.txt") | ||
with open(local_test_file, "w") as f: | ||
f.write("This is a test file") | ||
|
||
ftp_url = ftpserver.put_files(local_test_file, style="url", anon=anon) | ||
work_dir = os.path.join(tmp_path, "work_dir") | ||
os.makedirs(work_dir) | ||
os.chdir(work_dir) | ||
local_test_download = url_tools.try_download(ftp_url)[0] | ||
with open(local_test_file) as original, open(local_test_download) as downloaded: | ||
assert original.read() == downloaded.read() |