"""Integration tests for the dtm_wallonia_1m built-in plugin.
These tests make real HTTP requests to download the tile-index shapefile and,
optionally, individual 1 m DTM tiles. Run them with::
pytest -m network wolfhece/_builtin_plugins/dtm_wallonia_1m/tests/ -v
They are skipped in offline / CI environments unless the ``network`` mark is
explicitly requested.
Geographic notes
----------------
All coordinates are in **EPSG:31370 (Belgian Lambert 1972)**.
The approximate geographic centre of Wallonia is around
x = 214 500 m, y = 98 000 m (Condroz plateau, near Ciney).
The 500 m × 500 m test window is centred there.
"""
from __future__ import annotations
import numpy as np
import pytest
# ---------------------------------------------------------------------------
# Shared geometry helpers
# ---------------------------------------------------------------------------
[docs]
def _make_bounds_vec(xmin: float, ymin: float, xmax: float, ymax: float):
"""Return a closed :class:`~wolfhece.PyVertexvectors.vector` bounding rectangle."""
from wolfhece.PyVertexvectors import vector
v = vector()
v.add_vertices_from_array(
np.array([[xmin, ymin],
[xmax, ymin],
[xmax, ymax],
[xmin, ymax]])
)
v.force_to_close()
return v
# Centre of Wallonia (Lambert 1972), 500 m × 500 m window
_CX, _CY = 214_500.0, 98_000.0
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
@pytest.mark.network
[docs]
class TestDtmWalloniaTiles:
"""Tests for the internal :class:`_DtmWalloniaTiles` tile manager."""
[docs]
def test_download_index(self):
"""The tile-index shapefile is downloaded (or retrieved from cache)."""
from wolfhece._builtin_plugins.dtm_wallonia_1m.companion import _DtmWalloniaTiles
tiles = _DtmWalloniaTiles()
assert tiles.idx_path.exists(), (
f"Tile-index shapefile not found at {tiles.idx_path}"
)
assert tiles.idx_path.suffix == '.shp'
# The Tiles object must expose at least one zone with vectors.
assert tiles._tiles.myzones, "Tile index is empty — no zones loaded."
total = sum(len(z.myvectors) for z in tiles._tiles.myzones)
assert total > 0, "Tile index has no tile entries."
@pytest.mark.network
[docs]
class TestDtmWallonia1mCompanion:
"""Tests for the public API of :class:`DtmWallonia1mCompanion`."""
[docs]
def test_get_dtm_returns_wolf_array(self):
"""``get_dtm_1m(vector)`` returns a valid WolfArray without a viewer."""
from unittest.mock import MagicMock
from wolfhece._builtin_plugins.dtm_wallonia_1m.companion import (
DtmWallonia1mCompanion,
)
from wolfhece.wolf_array import WolfArray
viewer = MagicMock()
companion = DtmWallonia1mCompanion()
companion.proxy.attach(viewer)
companion._dtm_service = None
bounds = _make_bounds_vec(_XMIN, _YMIN, _XMAX, _YMAX)
dtm = companion.get_dtm_1m(bounds)
assert isinstance(dtm, WolfArray)
assert dtm.array is not None