bbdcea57a7
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
import pytest
|
|
from unittest.mock import AsyncMock, patch, MagicMock
|
|
|
|
|
|
def test_parse_open_meteo_response():
|
|
"""parse_forecast() should extract daily data into a clean list."""
|
|
from fabledassistant.services.weather import parse_forecast
|
|
raw = {
|
|
"daily": {
|
|
"time": ["2026-03-11", "2026-03-12"],
|
|
"temperature_2m_max": [15.0, 12.0],
|
|
"temperature_2m_min": [8.0, 6.0],
|
|
"precipitation_sum": [0.0, 3.2],
|
|
"weathercode": [0, 61],
|
|
"windspeed_10m_max": [10.0, 25.0],
|
|
}
|
|
}
|
|
days = parse_forecast(raw)
|
|
assert len(days) == 2
|
|
assert days[0]["date"] == "2026-03-11"
|
|
assert days[0]["temp_max"] == 15.0
|
|
assert days[0]["temp_min"] == 8.0
|
|
assert days[0]["precip_mm"] == 0.0
|
|
assert days[0]["weathercode"] == 0
|
|
assert days[1]["date"] == "2026-03-12"
|
|
assert days[1]["precip_mm"] == 3.2
|
|
|
|
|
|
def test_describe_weathercode():
|
|
"""describe_weathercode() should return human-readable strings."""
|
|
from fabledassistant.services.weather import describe_weathercode
|
|
assert describe_weathercode(0) == "Clear sky"
|
|
assert describe_weathercode(61) == "Rain: slight"
|
|
assert describe_weathercode(95) == "Thunderstorm"
|
|
assert "Unknown" in describe_weathercode(999)
|
|
|
|
|
|
def test_detect_forecast_changes_no_change():
|
|
"""detect_changes() should return empty list when forecasts are identical."""
|
|
from fabledassistant.services.weather import detect_changes
|
|
day = {"date": "2026-03-12", "temp_max": 12.0, "temp_min": 6.0,
|
|
"precip_mm": 3.2, "weathercode": 61}
|
|
assert detect_changes([day], [day]) == []
|
|
|
|
|
|
def test_detect_forecast_changes_rain_added():
|
|
"""detect_changes() should flag when precipitation appears."""
|
|
from fabledassistant.services.weather import detect_changes
|
|
old = [{"date": "2026-03-12", "temp_max": 14.0, "temp_min": 8.0,
|
|
"precip_mm": 0.0, "weathercode": 2}]
|
|
new = [{"date": "2026-03-12", "temp_max": 12.0, "temp_min": 7.0,
|
|
"precip_mm": 4.5, "weathercode": 61}]
|
|
changes = detect_changes(old, new)
|
|
assert len(changes) == 1
|
|
assert "2026-03-12" in changes[0]
|
|
assert "rain" in changes[0].lower() or "precip" in changes[0].lower()
|