test_bookings.py
tests/test_bookings.py
from datetime import datetime
import pytest
from bookings import Slot, can_book
def slot(start: str, end: str) -> Slot:
day = "2026-11-20T"
return Slot(datetime.fromisoformat(day + start), datetime.fromisoformat(day + end))
def test_un_creneau_libre_est_accepte():
assert can_book([], slot("10:00", "11:00"))
@pytest.mark.parametrize(
("debut", "fin"),
[("10:30", "11:30"), ("09:30", "10:30"), ("10:15", "10:45"), ("09:00", "12:00")],
)
def test_un_chevauchement_est_refuse(debut: str, fin: str):
assert not can_book([slot("10:00", "11:00")], slot(debut, fin))
def test_deux_creneaux_qui_se_touchent_ne_se_chevauchent_pas():
assert can_book([slot("10:00", "11:00")], slot("11:00", "12:00"))
def test_un_creneau_a_l_envers_est_refuse():
with pytest.raises(ValueError):
slot("11:00", "10:00")