Aglimate / tests /test_climate_intelligence.py
nexusbert's picture
feat: Enhance climate intelligence and WaPOR integration
844f884
Raw
History Blame Contribute Delete
1.32 kB
from app.utils.climate_intelligence import (
build_climate_intelligence_context,
extract_nigeria_location,
infer_crop_and_growth_stage,
)
def test_build_climate_intelligence_context_contains_climate_risk_and_recommendations():
context = build_climate_intelligence_context(
latitude=10.0,
longitude=7.0,
crop="maize",
growth_stage="pre-planting",
days=7,
)
assert isinstance(context, dict)
assert "location" in context
assert "current_weather" in context
assert "forecast" in context
assert "climate_risk" in context
assert "recommendations" in context
assert context["location"]["country"] == "Nigeria"
assert context["climate_risk"] in {"low", "medium", "high"}
assert isinstance(context["recommendations"], list)
assert context["recommendations"]
def test_extract_nigeria_location_handles_lagos_and_ikeja():
assert extract_nigeria_location("What is the weather like in Lagos?")[0] == "Lagos"
assert extract_nigeria_location("Ikeja weather forecast")[0] == "Ikeja"
def test_infer_crop_and_growth_stage_handles_farm_questions():
crop, stage = infer_crop_and_growth_stage("Should I plant maize in Kaduna before the rains?")
assert crop == "maize"
assert stage in {"pre-planting", "planting"}