Skip to content

Commit 2d70844

Browse files
committed
Avoid network access in ESA WorldCover Test
1 parent 86cb4eb commit 2d70844

6 files changed

+25
-5
lines changed

apps/dc_tools/odc/apps/dc_tools/esa_worldcover_to_dc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def esa_wc_to_dc(
204204
sys.stdout.write(f"\rAdded {success} datasets...")
205205
except rasterio.errors.RasterioIOError:
206206
logging.info("Couldn't read file %s", uri, exc_info=True)
207+
failure += 1
207208
except Exception: # pylint:disable=broad-except
208209
logging.exception("Failed to handle uri %s", uri)
209210
failure += 1
4.96 KB
Binary file not shown.
14.3 KB
Binary file not shown.
28.4 KB
Binary file not shown.
36 KB
Binary file not shown.

apps/dc_tools/tests/test_esa_worldcover_to_dc.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
from pathlib import Path
2+
13
import pytest
24
from click.testing import CliRunner
35

4-
from odc.apps.dc_tools.esa_worldcover_to_dc import _unpack_bbox, cli, get_tile_uris
6+
from odc.apps.dc_tools.esa_worldcover_to_dc import (
7+
_unpack_bbox,
8+
cli,
9+
get_tile_uris,
10+
URI_TEMPLATE,
11+
)
512

613

714
@pytest.fixture
@@ -43,6 +50,7 @@ def test_get_dem_tile_uris(bbox):
4350
"v100/2020/map/ESA_WorldCover_10m_2020_v100_N03E003_Map.tif"
4451
)
4552

53+
print(uris)
4654
assert len(uris) == 4
4755

4856

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

5462

55-
# Test the actual process
56-
def test_indexing_cli(bbox, odc_test_db_with_products):
63+
@pytest.fixture
64+
def mock_esa_worldcover_datasets(monkeypatch):
65+
"""Replace the fetching of remote ESA WorldCover datasets with local downsampled versions"""
66+
fname_template = URI_TEMPLATE.split("/")[-1]
67+
local_template = (
68+
"file://"
69+
+ str(Path(__name__).parent.absolute())
70+
+ f"/data/esa_worldcover/{fname_template}"
71+
)
72+
monkeypatch.setattr(
73+
"odc.apps.dc_tools.esa_worldcover_to_dc.URI_TEMPLATE", local_template
74+
)
75+
76+
77+
def test_indexing_cli(bbox, odc_test_db_with_products, mock_esa_worldcover_datasets):
5778
runner = CliRunner()
5879
result = runner.invoke(
5980
cli,
6081
[
6182
"--bbox",
6283
bbox,
63-
"--statsd-setting",
64-
"localhost:8125",
6584
],
6685
)
6786
assert result.exit_code == 0

0 commit comments

Comments
 (0)