Skip to content

Commit

Permalink
Avoid network access in ESA WorldCover Test
Browse files Browse the repository at this point in the history
  • Loading branch information
omad committed Jul 18, 2023
1 parent 3ffca17 commit 31a260c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 5 deletions.
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

0 comments on commit 31a260c

Please sign in to comment.