Resto·Ka — tous les restaurants du Québec, menus complets et prix réels (famille ·Ka)
Python 69.3%
TypeScript 16.7%
CSS 7.9%
JavaScript 4.7%
HTML 1.4%
1# ==============================================================================2# Author: Simon-Pierre Boucher <contact@spboucher.ai>3# File: tests/test_normalize.py4# Desc: Normalisation : parsing des prix (l'actif le plus critique),5# cuisines, type d'établissement, fourchette de prix, régions.6# ==============================================================================7from restoka.normalize import (8 classify_cuisines,9 classify_establishment,10 clean_name,11 parse_price,12 price_range_from_menu,13)14from restoka.regions import attach_region151617class TestParsePrice:18 def test_nombre(self):19 assert parse_price(14.29) == 14.292021 def test_texte_virgule(self):22 assert parse_price("16,50 $") == 16.502324 def test_texte_point(self):25 assert parse_price("à partir de 12.75$") == 12.752627 def test_zero_et_negatif(self):28 assert parse_price(0) is None29 assert parse_price(-3) is None3031 def test_vide(self):32 assert parse_price(None) is None33 assert parse_price("gratuit") is None343536class TestCuisines:37 def test_pizza(self):38 assert "pizza" in classify_cuisines("Pizza Mia")3940 def test_sushi(self):41 assert "sushi-japonais" in classify_cuisines("Ryu Sushi")4243 def test_menu_texte(self):44 cuisines = classify_cuisines("Chez Georges", "Poutine Tourtière Smoked meat")45 assert "quebecois" in cuisines4647 def test_inconnu(self):48 assert classify_cuisines("Xyzzy") == ["autre"]495051class TestEstablishment:52 def test_cafe(self):53 assert classify_establishment("Café Station W", []) == "cafe"5455 def test_boba(self):56 assert classify_establishment("Panda Boba-T", []) == "cafe"5758 def test_defaut(self):59 assert classify_establishment("Chez Georges", ["italien"]) == "restaurant"606162class TestPriceRange:63 def _menu(self, prices):64 return {"sections": [{"name": "Plats",65 "items": [{"name": f"p{i}", "price": p}66 for i, p in enumerate(prices)]}]}6768 def test_dollar(self):69 assert price_range_from_menu(self._menu([8, 10, 12])) == "$"7071 def test_deux_dollars(self):72 assert price_range_from_menu(self._menu([16, 22, 28])) == "$$"7374 def test_quatre_dollars(self):75 assert price_range_from_menu(self._menu([70, 95, 120])) == "$$$$"7677 def test_vide(self):78 assert price_range_from_menu(None) == ""798081class TestRegions:82 def test_villes(self):83 assert attach_region("Montréal") == "Montréal"84 assert attach_region("Québec") == "Capitale-Nationale"85 assert attach_region("Lévis") == "Chaudière-Appalaches"86 assert attach_region("Sherbrooke") == "Estrie"87 assert attach_region("Saguenay") == "Saguenay–Lac-Saint-Jean"88 assert attach_region("Gaspé") == "Gaspésie–Îles-de-la-Madeleine"89 assert attach_region("Laval") == "Laval"90 assert attach_region("Brossard") == "Montérégie"9192 def test_accents_et_casse(self):93 assert attach_region("MONTREAL") == "Montréal"94 assert attach_region("Trois-Rivieres") == "Mauricie"9596 def test_repli_postal(self):97 assert attach_region("Village-inconnu", "G1R 4P5") == "Capitale-Nationale"98 assert attach_region("Village-inconnu", "H7E 0H3") == "Laval"99 assert attach_region("Village-inconnu", "J1N 2A7") == "Estrie"100101 def test_jamais_inventee(self):102 assert attach_region("Ottawa") == ""103104105def test_clean_name():106 assert clean_name(" CRÈME BRÛLÉE ") == "Crème Brûlée"107 assert clean_name("Pizza <b>Mia</b>") == "Pizza Mia"108