Fuel Advisor: stations reelles avec Waze/Google Maps, liste depliable, enseignes sans monogramme, contexte marche et Brent quotidien FRED
57 stations renvoyees au lieu de 12; cout reel par option (carburant + detour marginal) et ecart en euros; bouton Afficher les N autres stations alimente par un compte serveur teste (0/1-2/3/>3); pictogramme neutre + nom complet, aucun logo de marque tierce; Brent DCOILBRENTEU (EIA via FRED) quotidien avec date d observation reelle; sections techniques repliees.
This commit is contained in:
83
tests/test_brent.py
Normal file
83
tests/test_brent.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Brent quotidien : parsing, âge réel et absence de report de valeur."""
|
||||
|
||||
import sqlite3
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
|
||||
import brent
|
||||
|
||||
HEADER = "observation_date,DCOILBRENTEU\n"
|
||||
FIXTURE = HEADER + "2026-09-07,104.47\n2026-09-08,.\n2026-09-09,109.51\n2026-09-10,\n"
|
||||
|
||||
|
||||
def memory():
|
||||
db = sqlite3.connect(":memory:")
|
||||
db.row_factory = sqlite3.Row
|
||||
return db
|
||||
|
||||
|
||||
def test_parse_ignore_les_valeurs_manquantes():
|
||||
rows = brent.parse(FIXTURE)
|
||||
assert rows == [("2026-09-07", 104.47), ("2026-09-09", 109.51)]
|
||||
|
||||
|
||||
def test_parse_rejette_une_valeur_non_exploitable():
|
||||
assert brent.parse(HEADER + "2026-09-09,-3.2\n") == []
|
||||
assert brent.parse(HEADER + "2026-09-09,abc\n") == []
|
||||
|
||||
|
||||
def test_refresh_conserve_la_date_d_observation_et_fetched_at_distincts():
|
||||
db = memory()
|
||||
report = brent.refresh(db=db, text=FIXTURE, fetched_at="2026-09-11T06:00:00+00:00")
|
||||
assert report["stored"] == 2
|
||||
row = db.execute("SELECT * FROM brent_daily ORDER BY observed_at").fetchone()
|
||||
assert row["observed_at"] == "2026-09-07"
|
||||
assert row["available_at"] == "2026-09-08"
|
||||
assert row["fetched_at"] == "2026-09-11T06:00:00+00:00"
|
||||
assert row["source"] == "EIA via FRED"
|
||||
|
||||
|
||||
def test_aucun_report_de_valeur_sur_une_journee_absente():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
days = [row[0] for row in db.execute("SELECT observed_at FROM brent_daily ORDER BY 1")]
|
||||
assert days == ["2026-09-07", "2026-09-09"] # le 08 et le 10 n'existent pas, pas de report
|
||||
|
||||
|
||||
def test_refresh_ne_reecrit_pas_une_observation_connue():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
assert brent.count(db) == 2
|
||||
|
||||
|
||||
def test_latest_annonce_la_derniere_observation_disponible_quand_elle_vieillit():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
block = brent.latest(db=db, today=date(2026, 9, 20))
|
||||
assert block["usd_per_barrel"] == 109.51
|
||||
assert block["age_days"] == 11
|
||||
assert block["stale"] is True
|
||||
assert block["summary"] == "Dernière observation disponible il y a 11 jours"
|
||||
assert block["summary"] != "cours du jour"
|
||||
|
||||
|
||||
def test_latest_affiche_la_date_quand_l_observation_est_recente():
|
||||
db = memory()
|
||||
brent.refresh(db=db, text=FIXTURE)
|
||||
block = brent.latest(db=db, today=date(2026, 9, 10))
|
||||
assert block["stale"] is False
|
||||
assert block["summary"] == "Observation du 09/09/2026"
|
||||
|
||||
|
||||
def test_latest_sans_donnee_ne_pretend_pas_a_un_prix():
|
||||
block = brent.latest(db=memory())
|
||||
assert block["available"] is False
|
||||
assert block["summary"] == "Brent spot temporairement indisponible"
|
||||
assert "usd_per_barrel" not in block
|
||||
|
||||
|
||||
def test_refresh_refuse_une_serie_vide():
|
||||
with pytest.raises(ValueError):
|
||||
brent.refresh(db=memory(), text="")
|
||||
Reference in New Issue
Block a user