File size: 1,580 Bytes
e7194cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Tests rapides : python -m pytest -q   (ou python tests/test_grapp.py)"""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from grapp.carte import trouver_vins
from grapp.engine import DicoVino, Grapp, Preferences

G = Grapp(use_hf=False)
NOMS = G.vins["nom"].tolist()


def test_filtre_couleur_et_bulles():
    r = G.recommander(Preferences(couleur="blanc", bulles="oui"), k=10)
    assert r and all(x.vin["couleur"] == "blanc" and x.vin["bulles"] == 1 for x in r)


def test_huitres_donne_un_blanc_mineral():
    p = Preferences(couleur="blanc", familles=["mineral"], occasion="repas",
                    format="bouteille", budget=25, envie="huîtres et fruits de mer")
    assert G.recommander(p, k=1)[0].vin["famille"] == "mineral"


def test_lecture_carte_tolere_fautes_ocr():
    texte = "Cétes du Rhone, E. Guigal 2021 27€\nChampagne Brut, Maison X 68 €\nChablis ler Cru 48 €"
    res = {x["nom"]: x["prix_carte"] for x in trouver_vins(texte, NOMS)}
    assert res == {"Côtes du Rhône": 27.0, "Champagne Brut": 68.0, "Chablis": 48.0}


def test_reco_limitee_a_la_carte_et_prix_resto():
    r = G.recommander(Preferences(format="bouteille"), carte={"Chinon": 29.0, "Tavel": 30.0})
    assert {x.nom for x in r} <= {"Chinon", "Tavel"} and {x.prix for x in r} <= {29.0, 30.0}


def test_dico():
    assert "Tanins" in DicoVino(use_hf=False).chercher("tanins")["terme"].tolist()


if __name__ == "__main__":
    for n, f in list(globals().items()):
        if n.startswith("test_"):
            f(); print("OK", n)