parent
7a50ea6016
commit
61e17d9c96
10 changed files with 416 additions and 4 deletions
50
tests/test_school_holiday.py
Normal file
50
tests/test_school_holiday.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""Tests for UK school holiday parsing."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from agenda import uk_school_holiday
|
||||
|
||||
|
||||
def test_parse_school_holidays_from_ics() -> None:
|
||||
"""Parse holiday ranges and skip bank-holiday events."""
|
||||
ics_text = """BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART;VALUE=DATE:20260525
|
||||
DTEND;VALUE=DATE:20260601
|
||||
SUMMARY;LANGUAGE=en-gb:Half Term Holiday (Bristol notes)
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTART;VALUE=DATE:20260831
|
||||
DTEND;VALUE=DATE:20260901
|
||||
SUMMARY;LANGUAGE=en-gb:Summer Bank Holiday
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
"""
|
||||
|
||||
parsed = uk_school_holiday.parse_school_holidays_from_ics(ics_text)
|
||||
assert len(parsed) == 1
|
||||
assert parsed[0].name == "uk_school_holiday"
|
||||
assert parsed[0].title == "Half Term Holiday"
|
||||
assert parsed[0].as_date == datetime.date(2026, 5, 25)
|
||||
assert parsed[0].end_as_date == datetime.date(2026, 5, 31)
|
||||
|
||||
|
||||
def test_school_holiday_list_filters_overlap(tmp_path: Path) -> None:
|
||||
"""Filter cached school holiday ranges by overlap."""
|
||||
filename = uk_school_holiday.json_filename(str(tmp_path))
|
||||
with open(filename, "w", encoding="utf-8") as out:
|
||||
out.write(
|
||||
'[{"name":"uk_school_holiday","title":"Easter Holiday",'
|
||||
'"start":"2026-04-01","end":"2026-04-12","url":""}]'
|
||||
)
|
||||
|
||||
events = uk_school_holiday.school_holiday_list(
|
||||
datetime.date(2026, 4, 10),
|
||||
datetime.date(2026, 4, 20),
|
||||
str(tmp_path),
|
||||
)
|
||||
assert len(events) == 1
|
||||
assert events[0].title == "Easter Holiday"
|
||||
Loading…
Add table
Add a link
Reference in a new issue