Afficher les enseignes, ajouter un fournisseur pétrole en secours et tracer les prix
Enseignes via OpenStreetMap/Nominatim (cache 30 jours, correspondance a 120 m, aucune enseigne inventee). Cotation du petrole en chaine stooq puis page publique, conversion euro avec la BCE, jamais de fausse stabilite. Graphes moyenne journaliere des releves et une courbe par station. Noms de stations et type de voie conserves pour l affichage.
This commit is contained in:
61
tests/test_brands.py
Normal file
61
tests/test_brands.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import importlib
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def brands(monkeypatch, tmp_path):
|
||||
assert importlib.util.find_spec("brands"), "Module enseignes absent"
|
||||
module = importlib.import_module("brands")
|
||||
monkeypatch.setattr(module, "DB_PATH", tmp_path / "brands.sqlite3")
|
||||
return module
|
||||
|
||||
|
||||
CANDIDATES = [
|
||||
{"lat": 47.2186, "lon": -1.5541, "name": "Total", "brand": "TotalEnergies"},
|
||||
{"lat": 47.2400, "lon": -1.6100, "name": "Carrefour", "brand": None, "operator": "Carrefour"},
|
||||
]
|
||||
|
||||
|
||||
def test_normalise_prefers_brand_then_operator_then_name(brands):
|
||||
assert brands.label_from_tags({"brand": "Esso", "operator": "X", "name": "Y"}) == "Esso"
|
||||
assert brands.label_from_tags({"operator": "E.Leclerc", "name": "Y"}) == "E.Leclerc"
|
||||
assert brands.label_from_tags({"name": "Station du port"}) == "Station du port"
|
||||
assert brands.label_from_tags({}) is None
|
||||
assert brands.label_from_tags({"brand": " ", "operator": "BP"}) == "BP"
|
||||
|
||||
|
||||
def test_match_requires_proximity(brands):
|
||||
near = {"lat": 47.21865, "lon": -1.55415}
|
||||
far = {"lat": 47.2300, "lon": -1.5700}
|
||||
assert brands.match(near, CANDIDATES) == "TotalEnergies"
|
||||
assert brands.match(far, CANDIDATES) is None
|
||||
assert brands.match(near, []) is None
|
||||
|
||||
|
||||
def test_attach_adds_label_and_keeps_stations_without_match(brands):
|
||||
stations = [{"lat": 47.21865, "lon": -1.55415, "name": "A"}, {"lat": 49.0, "lon": 2.0, "name": "B"}]
|
||||
out = brands.attach(stations, CANDIDATES)
|
||||
assert out[0]["brand"] == "TotalEnergies"
|
||||
assert out[1]["brand"] is None
|
||||
|
||||
|
||||
def test_cache_roundtrip_and_source_failure_is_not_fatal(brands, monkeypatch):
|
||||
calls = []
|
||||
|
||||
def source(lat, lon, radius):
|
||||
calls.append((lat, lon, radius))
|
||||
return CANDIDATES
|
||||
|
||||
first = brands.candidates(47.2186, -1.5541, 15, source=source)
|
||||
second = brands.candidates(47.2186, -1.5541, 15, source=source)
|
||||
assert first == second == CANDIDATES
|
||||
assert len(calls) == 1, "le cache doit éviter un second appel"
|
||||
|
||||
def broken(lat, lon, radius):
|
||||
raise OSError("nominatim indisponible")
|
||||
|
||||
assert brands.candidates(48.0, 2.0, 10, source=broken) == []
|
||||
assert brands.attach([{"lat": 48.0, "lon": 2.0, "name": "C"}], []) == [
|
||||
{"lat": 48.0, "lon": 2.0, "name": "C", "brand": None}
|
||||
]
|
||||
Reference in New Issue
Block a user