KSvend commited on
Commit ·
46ca87a
1
Parent(s): 30f032f
feat: add test fixtures for EO product overhaul
Browse files- tests/__init__.py +0 -0
- tests/conftest.py +69 -0
tests/__init__.py
ADDED
|
File without changes
|
tests/conftest.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Shared test fixtures for Aperture tests."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@pytest.fixture
|
| 9 |
+
def synthetic_monthly_raster(tmp_path):
|
| 10 |
+
"""Create a synthetic multi-band GeoTIFF with 12 monthly bands.
|
| 11 |
+
|
| 12 |
+
Returns a factory function: call with (n_bands, shape, fill_fn) to get a path.
|
| 13 |
+
fill_fn(band_idx) -> 2D numpy array.
|
| 14 |
+
"""
|
| 15 |
+
import rasterio
|
| 16 |
+
from rasterio.transform import from_bounds
|
| 17 |
+
|
| 18 |
+
def _make(
|
| 19 |
+
n_bands: int = 12,
|
| 20 |
+
shape: tuple[int, int] = (100, 100),
|
| 21 |
+
fill_fn=None,
|
| 22 |
+
bbox: tuple[float, ...] = (37.8, 2.08, 37.88, 2.17),
|
| 23 |
+
) -> str:
|
| 24 |
+
if fill_fn is None:
|
| 25 |
+
fill_fn = lambda i: np.random.default_rng(i).uniform(0.2, 0.8, shape).astype(np.float32)
|
| 26 |
+
|
| 27 |
+
path = str(tmp_path / f"synthetic_{n_bands}bands.tif")
|
| 28 |
+
transform = from_bounds(*bbox, shape[1], shape[0])
|
| 29 |
+
with rasterio.open(
|
| 30 |
+
path, "w", driver="GTiff",
|
| 31 |
+
height=shape[0], width=shape[1],
|
| 32 |
+
count=n_bands, dtype="float32",
|
| 33 |
+
crs="EPSG:4326", transform=transform,
|
| 34 |
+
nodata=-9999.0,
|
| 35 |
+
) as dst:
|
| 36 |
+
for i in range(n_bands):
|
| 37 |
+
dst.write(fill_fn(i), i + 1)
|
| 38 |
+
return path
|
| 39 |
+
|
| 40 |
+
return _make
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@pytest.fixture
|
| 44 |
+
def mock_indicator_result():
|
| 45 |
+
"""Factory for IndicatorResult with sensible defaults."""
|
| 46 |
+
from app.models import IndicatorResult, StatusLevel, TrendDirection, ConfidenceLevel
|
| 47 |
+
|
| 48 |
+
def _make(**overrides):
|
| 49 |
+
defaults = dict(
|
| 50 |
+
indicator_id="ndvi",
|
| 51 |
+
headline="Test headline",
|
| 52 |
+
status=StatusLevel.GREEN,
|
| 53 |
+
trend=TrendDirection.STABLE,
|
| 54 |
+
confidence=ConfidenceLevel.HIGH,
|
| 55 |
+
map_layer_path="/tmp/fake.tif",
|
| 56 |
+
chart_data={"dates": [], "values": []},
|
| 57 |
+
summary="Test summary",
|
| 58 |
+
methodology="Test methodology",
|
| 59 |
+
limitations=["Test limitation"],
|
| 60 |
+
data_source="satellite",
|
| 61 |
+
anomaly_months=0,
|
| 62 |
+
z_score_current=0.0,
|
| 63 |
+
hotspot_pct=0.0,
|
| 64 |
+
confidence_factors={},
|
| 65 |
+
)
|
| 66 |
+
defaults.update(overrides)
|
| 67 |
+
return IndicatorResult(**defaults)
|
| 68 |
+
|
| 69 |
+
return _make
|