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_hours.py4# Desc: Parseur d'horaires — syntaxes OSM courantes structurées par jour,5# cas exotiques refusés (le brut reste dans hours["osm"]), horaires6# JSON-LD schema.org (openingHoursSpecification / openingHours).7# ==============================================================================8from restoka.hours import parse_jsonld_hours, parse_opening_hours91011def test_plages_de_jours_simples():12 h = parse_opening_hours("Mo-Fr 11:00-22:00; Sa-Su 10:00-23:00")13 assert h["mon"] == [["11:00", "22:00"]]14 assert h["fri"] == [["11:00", "22:00"]]15 assert h["sat"] == [["10:00", "23:00"]]16 assert h["sun"] == [["10:00", "23:00"]]171819def test_double_service_et_jour_off():20 h = parse_opening_hours("Tu-Sa 11:30-14:00,17:00-22:00; Su-Mo off")21 assert h["tue"] == [["11:30", "14:00"], ["17:00", "22:00"]]22 assert h["sun"] == [] and h["mon"] == []232425def test_24_7_et_liste_de_jours():26 assert parse_opening_hours("24/7")["wed"] == [["00:00", "24:00"]]27 h = parse_opening_hours("Mo,We,Fr 09:00-17:00")28 assert set(h) == {"mon", "wed", "fri"}293031def test_heures_seules_et_enroulement_semaine():32 assert parse_opening_hours("08:00-16:00")["sun"] == [["08:00", "16:00"]]33 h = parse_opening_hours("Sa-Mo 10:00-15:00") # enroule Sa, Su, Mo34 assert set(h) == {"sat", "sun", "mon"}353637def test_ph_ignore_et_exotique_refuse():38 h = parse_opening_hours("Mo-Fr 11:00-22:00; PH off")39 assert h["mon"] == [["11:00", "22:00"]] and "ph" not in h40 assert parse_opening_hours("Mo-Fr sunrise-sunset") is None41 assert parse_opening_hours("Jun-Aug Mo-Su 10:00-22:00") is None42 assert parse_opening_hours("") is None43 assert parse_opening_hours(None) is None444546def test_jsonld_opening_hours_specification():47 node = {"@type": "Restaurant", "openingHoursSpecification": [48 {"dayOfWeek": ["Monday", "Tuesday"], "opens": "11:00", "closes": "22:00"},49 {"dayOfWeek": "https://schema.org/Sunday", "opens": "10:00",50 "closes": "15:00"},51 ]}52 h = parse_jsonld_hours(node)53 assert h["mon"] == [["11:00", "22:00"]]54 assert h["sun"] == [["10:00", "15:00"]]555657def test_jsonld_opening_hours_chaines():58 h = parse_jsonld_hours({"openingHours": ["Mo-Fr 11:00-22:00"]})59 assert h["thu"] == [["11:00", "22:00"]]60 assert parse_jsonld_hours({}) is None61