-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added parameters and exception behaviour to pqdm (#792)
Co-authored-by: Chuck Daniels <[email protected]> Co-authored-by: Matt Fisher <[email protected]>
- Loading branch information
1 parent
9784e4c
commit 84be54e
Showing
4 changed files
with
127 additions
and
11 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
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 @@ | ||
from unittest.mock import Mock | ||
|
||
import earthaccess | ||
import pytest | ||
|
||
|
||
def test_download_immediate_failure(monkeypatch): | ||
earthaccess.login() | ||
|
||
results = earthaccess.search_data( | ||
short_name="ATL06", | ||
bounding_box=(-10, 20, 10, 50), | ||
temporal=("1999-02", "2019-03"), | ||
count=10, | ||
) | ||
|
||
def mock_get(*args, **kwargs): | ||
raise Exception("Download failed") | ||
|
||
mock_store = Mock() | ||
monkeypatch.setattr(earthaccess, "__store__", mock_store) | ||
monkeypatch.setattr(mock_store, "get", mock_get) | ||
|
||
with pytest.raises(Exception, match="Download failed"): | ||
earthaccess.download(results, "/home/download-folder") | ||
|
||
|
||
def test_download_deferred_failure(monkeypatch): | ||
earthaccess.login() | ||
|
||
results = earthaccess.search_data( | ||
short_name="ATL06", | ||
bounding_box=(-10, 20, 10, 50), | ||
temporal=("1999-02", "2019-03"), | ||
count=10, | ||
) | ||
|
||
def mock_get(*args, **kwargs): | ||
return [Exception("Download failed")] * len(results) | ||
|
||
mock_store = Mock() | ||
monkeypatch.setattr(earthaccess, "__store__", mock_store) | ||
monkeypatch.setattr(mock_store, "get", mock_get) | ||
|
||
results = earthaccess.download( | ||
results, "/home/download-folder", None, 8, {"exception_behavior": "deferred"} | ||
) | ||
|
||
assert all(isinstance(e, Exception) for e in results) | ||
assert len(results) == 10 |