Skip to content

Commit

Permalink
Change pqdm download tests to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckwondo committed Nov 5, 2024
1 parent 7b7b132 commit cf77990
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: mypy

- name: Test
run: pytest tests/unit --cov=earthaccess --cov=tests --cov-report=term-missing --capture=no --tb=native --log-cli-level=INFO
run: pytest tests/unit --verbose --cov=earthaccess --cov-report=term-missing --capture=no --tb=native --log-cli-level=INFO

- name: Upload coverage
# Don't upload coverage when using the `act` tool to run the workflow locally
Expand Down
2 changes: 1 addition & 1 deletion scripts/integration-test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

set -x
pytest tests/integration --cov=earthaccess --cov=tests/integration --cov-report=term-missing "${@}" --capture=no --tb=native --log-cli-level=INFO
pytest tests/integration --cov=earthaccess --cov-report=term-missing "${@}" --capture=no --tb=native --log-cli-level=INFO
RET=$?
set +x

Expand Down
46 changes: 46 additions & 0 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
from pathlib import Path
from unittest.mock import patch

import earthaccess
import pytest
Expand Down Expand Up @@ -77,6 +78,51 @@ def test_download(tmp_path, selection, use_url):
assert all(Path(f).exists() for f in files)


def fail_to_download_file(*args, **kwargs):
raise IOError("Download failed")


def test_download_immediate_failure(tmp_path: Path):
results = earthaccess.search_data(
short_name="ATL06",
bounding_box=(-10, 20, 10, 50),
temporal=("1999-02", "2019-03"),
count=3,
)

with patch.object(earthaccess.__store__, "_download_file", fail_to_download_file):
with pytest.raises(IOError, match="Download failed"):
# By default, we set pqdm exception_behavior to "immediate" so that
# it simply propagates the first download error it encounters, halting
# any further downloads.
earthaccess.download(results, tmp_path, pqdm_kwargs=dict(disable=True))


def test_download_deferred_failure(tmp_path: Path):
count = 3
results = earthaccess.search_data(
short_name="ATL06",
bounding_box=(-10, 20, 10, 50),
temporal=("1999-02", "2019-03"),
count=count,
)

with patch.object(earthaccess.__store__, "_download_file", fail_to_download_file):
# With "deferred" exceptions, pqdm catches all exceptions, then at the end
# raises a single generic Exception, passing the sequence of caught exceptions
# as arguments to the Exception constructor.
with pytest.raises(Exception) as exc_info:
earthaccess.download(
results,
tmp_path,
pqdm_kwargs=dict(exception_behaviour="deferred", disable=True),
)

errors = exc_info.value.args
assert len(errors) == count
assert all(isinstance(e, IOError) and str(e) == "Download failed" for e in errors)


def test_auth_environ():
earthaccess.login(strategy="environment")
environ = earthaccess.auth_environ()
Expand Down
50 changes: 0 additions & 50 deletions tests/unit/test_api.py

This file was deleted.

0 comments on commit cf77990

Please sign in to comment.