# ============================================================================== # Author: Simon-Pierre Boucher # File: tests/test_hours.py # Desc: Parseur d'horaires — syntaxes OSM courantes structurées par jour, # cas exotiques refusés (le brut reste dans hours["osm"]), horaires # JSON-LD schema.org (openingHoursSpecification / openingHours). # ============================================================================== from restoka.hours import parse_jsonld_hours, parse_opening_hours def test_plages_de_jours_simples(): h = parse_opening_hours("Mo-Fr 11:00-22:00; Sa-Su 10:00-23:00") assert h["mon"] == [["11:00", "22:00"]] assert h["fri"] == [["11:00", "22:00"]] assert h["sat"] == [["10:00", "23:00"]] assert h["sun"] == [["10:00", "23:00"]] def test_double_service_et_jour_off(): h = parse_opening_hours("Tu-Sa 11:30-14:00,17:00-22:00; Su-Mo off") assert h["tue"] == [["11:30", "14:00"], ["17:00", "22:00"]] assert h["sun"] == [] and h["mon"] == [] def test_24_7_et_liste_de_jours(): assert parse_opening_hours("24/7")["wed"] == [["00:00", "24:00"]] h = parse_opening_hours("Mo,We,Fr 09:00-17:00") assert set(h) == {"mon", "wed", "fri"} def test_heures_seules_et_enroulement_semaine(): assert parse_opening_hours("08:00-16:00")["sun"] == [["08:00", "16:00"]] h = parse_opening_hours("Sa-Mo 10:00-15:00") # enroule Sa, Su, Mo assert set(h) == {"sat", "sun", "mon"} def test_ph_ignore_et_exotique_refuse(): h = parse_opening_hours("Mo-Fr 11:00-22:00; PH off") assert h["mon"] == [["11:00", "22:00"]] and "ph" not in h assert parse_opening_hours("Mo-Fr sunrise-sunset") is None assert parse_opening_hours("Jun-Aug Mo-Su 10:00-22:00") is None assert parse_opening_hours("") is None assert parse_opening_hours(None) is None def test_jsonld_opening_hours_specification(): node = {"@type": "Restaurant", "openingHoursSpecification": [ {"dayOfWeek": ["Monday", "Tuesday"], "opens": "11:00", "closes": "22:00"}, {"dayOfWeek": "https://schema.org/Sunday", "opens": "10:00", "closes": "15:00"}, ]} h = parse_jsonld_hours(node) assert h["mon"] == [["11:00", "22:00"]] assert h["sun"] == [["10:00", "15:00"]] def test_jsonld_opening_hours_chaines(): h = parse_jsonld_hours({"openingHours": ["Mo-Fr 11:00-22:00"]}) assert h["thu"] == [["11:00", "22:00"]] assert parse_jsonld_hours({}) is None