Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid network access in ESA WorldCover Test #576

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/dc_tools/odc/apps/dc_tools/esa_worldcover_to_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def esa_wc_to_dc(
sys.stdout.write(f"\rAdded {success} datasets...")
except rasterio.errors.RasterioIOError:
logging.info("Couldn't read file %s", uri, exc_info=True)
failure += 1
except Exception: # pylint:disable=broad-except
logging.exception("Failed to handle uri %s", uri)
failure += 1
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 24 additions & 5 deletions apps/dc_tools/tests/test_esa_worldcover_to_dc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from pathlib import Path

import pytest
from click.testing import CliRunner

from odc.apps.dc_tools.esa_worldcover_to_dc import _unpack_bbox, cli, get_tile_uris
from odc.apps.dc_tools.esa_worldcover_to_dc import (
_unpack_bbox,
cli,
get_tile_uris,
URI_TEMPLATE,
)


@pytest.fixture
Expand Down Expand Up @@ -43,6 +50,7 @@ def test_get_dem_tile_uris(bbox):
"v100/2020/map/ESA_WorldCover_10m_2020_v100_N03E003_Map.tif"
)

print(uris)
assert len(uris) == 4


Expand All @@ -52,16 +60,27 @@ def test_complex_bbox(bbox_africa):
assert len(uris) == 899


# Test the actual process
def test_indexing_cli(bbox, odc_test_db_with_products):
@pytest.fixture
def mock_esa_worldcover_datasets(monkeypatch):
"""Replace the fetching of remote ESA WorldCover datasets with local downsampled versions"""
fname_template = URI_TEMPLATE.split("/")[-1]
local_template = (
"file://"
+ str(Path(__name__).parent.absolute())
+ f"/data/esa_worldcover/{fname_template}"
)
monkeypatch.setattr(
"odc.apps.dc_tools.esa_worldcover_to_dc.URI_TEMPLATE", local_template
)


def test_indexing_cli(bbox, odc_test_db_with_products, mock_esa_worldcover_datasets):
runner = CliRunner()
result = runner.invoke(
cli,
[
"--bbox",
bbox,
"--statsd-setting",
"localhost:8125",
],
)
assert result.exit_code == 0
Loading