Ajouter conseiller carburant

This commit is contained in:
Hermes Agent
2026-09-12 19:28:09 +02:00
commit 0c16962725
4 changed files with 490 additions and 0 deletions

29
tests/test_app.py Normal file
View File

@@ -0,0 +1,29 @@
import importlib.util
import sys
from pathlib import Path
spec = importlib.util.spec_from_file_location("fuel_app", Path(__file__).resolve().parents[1] / "app.py")
fuel_app = importlib.util.module_from_spec(spec)
assert spec and spec.loader
sys.modules["fuel_app"] = fuel_app
spec.loader.exec_module(fuel_app)
def test_haversine_paris_close():
d = fuel_app.haversine(48.8566, 2.3522, 48.8566, 2.3522)
assert d == 0
def test_advice_uses_best_price(monkeypatch):
rows = [
{"id": "1", "name": "A", "address": "rue A", "city": "Paris", "lat": 48.8566, "lon": 2.3522, "prices": {"Gazole": 1.70}, "updates": {"Gazole": "2026-01-01"}},
{"id": "2", "name": "B", "address": "rue B", "city": "Paris", "lat": 48.8570, "lon": 2.3530, "prices": {"Gazole": 1.82}, "updates": {"Gazole": "2026-01-01"}},
{"id": "3", "name": "C", "address": "rue C", "city": "Paris", "lat": 48.8580, "lon": 2.3540, "prices": {"Gazole": 1.80}, "updates": {"Gazole": "2026-01-01"}},
]
monkeypatch.setattr(fuel_app, "load_fuel_data", lambda: rows)
monkeypatch.setattr(fuel_app, "market_signal", lambda: {"summary": "pétrole flat", "trend": "flat", "delta_pct": 0})
monkeypatch.setattr(fuel_app, "news_signal", lambda: [])
monkeypatch.setattr(fuel_app, "ollama_summary", lambda context: (None, False))
out = fuel_app.advice(48.8566, 2.3522, "Gazole", 5)
assert out["stations"][0]["name"] == "A"
assert out["action"] == "buy"