| """Tests for updated narrative generation.""" |
| import pytest |
|
|
|
|
| def test_generate_narrative_includes_zscore_context(mock_product_result): |
| """Narrative references z-score context when anomaly data is present.""" |
| from app.outputs.narrative import generate_narrative |
|
|
| results = [ |
| mock_product_result( |
| product_id="ndvi", |
| status="amber", |
| headline="Vegetation decline (z=-1.8)", |
| z_score_current=-1.8, |
| anomaly_months=3, |
| ), |
| ] |
| text = generate_narrative(results) |
| assert "concern" in text.lower() or "monitoring" in text.lower() |
|
|
|
|
| def test_generate_compound_signals_text(): |
| """Compound signal text generated from CompoundSignal objects.""" |
| from app.outputs.narrative import generate_compound_signals_text |
| from app.models import CompoundSignal |
|
|
| signals = [ |
| CompoundSignal( |
| name="land_conversion", |
| triggered=True, |
| confidence="strong", |
| description="NDVI decline overlaps with settlement growth (45% overlap, 120 ha).", |
| indicators=["ndvi", "buildup"], |
| overlap_pct=45.0, |
| affected_ha=120.0, |
| ), |
| CompoundSignal( |
| name="flood_event", |
| triggered=False, |
| confidence="weak", |
| description="No flood signal detected.", |
| indicators=["sar", "water"], |
| ), |
| ] |
| text = generate_compound_signals_text(signals) |
| assert "Land Conversion" in text |
| assert "NDVI decline" in text |
|
|
|
|
| def test_no_compound_signals_text(): |
| """When no signals triggered, text says so explicitly.""" |
| from app.outputs.narrative import generate_compound_signals_text |
|
|
| text = generate_compound_signals_text([]) |
| assert "no compound" in text.lower() |
|
|