# ============================================================================== # Author: Simon-Pierre Boucher # File: tests/test_normalize.py # Desc: Normalisation : parsing des prix (l'actif le plus critique), # cuisines, type d'établissement, fourchette de prix, régions. # ============================================================================== from restoka.normalize import ( classify_cuisines, classify_establishment, clean_name, parse_price, price_range_from_menu, ) from restoka.regions import attach_region class TestParsePrice: def test_nombre(self): assert parse_price(14.29) == 14.29 def test_texte_virgule(self): assert parse_price("16,50 $") == 16.50 def test_texte_point(self): assert parse_price("à partir de 12.75$") == 12.75 def test_zero_et_negatif(self): assert parse_price(0) is None assert parse_price(-3) is None def test_vide(self): assert parse_price(None) is None assert parse_price("gratuit") is None class TestCuisines: def test_pizza(self): assert "pizza" in classify_cuisines("Pizza Mia") def test_sushi(self): assert "sushi-japonais" in classify_cuisines("Ryu Sushi") def test_menu_texte(self): cuisines = classify_cuisines("Chez Georges", "Poutine Tourtière Smoked meat") assert "quebecois" in cuisines def test_inconnu(self): assert classify_cuisines("Xyzzy") == ["autre"] class TestEstablishment: def test_cafe(self): assert classify_establishment("Café Station W", []) == "cafe" def test_boba(self): assert classify_establishment("Panda Boba-T", []) == "cafe" def test_defaut(self): assert classify_establishment("Chez Georges", ["italien"]) == "restaurant" class TestPriceRange: def _menu(self, prices): return {"sections": [{"name": "Plats", "items": [{"name": f"p{i}", "price": p} for i, p in enumerate(prices)]}]} def test_dollar(self): assert price_range_from_menu(self._menu([8, 10, 12])) == "$" def test_deux_dollars(self): assert price_range_from_menu(self._menu([16, 22, 28])) == "$$" def test_quatre_dollars(self): assert price_range_from_menu(self._menu([70, 95, 120])) == "$$$$" def test_vide(self): assert price_range_from_menu(None) == "" class TestRegions: def test_villes(self): assert attach_region("Montréal") == "Montréal" assert attach_region("Québec") == "Capitale-Nationale" assert attach_region("Lévis") == "Chaudière-Appalaches" assert attach_region("Sherbrooke") == "Estrie" assert attach_region("Saguenay") == "Saguenay–Lac-Saint-Jean" assert attach_region("Gaspé") == "Gaspésie–Îles-de-la-Madeleine" assert attach_region("Laval") == "Laval" assert attach_region("Brossard") == "Montérégie" def test_accents_et_casse(self): assert attach_region("MONTREAL") == "Montréal" assert attach_region("Trois-Rivieres") == "Mauricie" def test_repli_postal(self): assert attach_region("Village-inconnu", "G1R 4P5") == "Capitale-Nationale" assert attach_region("Village-inconnu", "H7E 0H3") == "Laval" assert attach_region("Village-inconnu", "J1N 2A7") == "Estrie" def test_jamais_inventee(self): assert attach_region("Ottawa") == "" def test_clean_name(): assert clean_name(" CRÈME BRÛLÉE ") == "Crème Brûlée" assert clean_name("Pizza Mia") == "Pizza Mia"