|
1 | 1 | """Tests for ICS files containing multiple VCALENDAR components.""" |
2 | 2 |
|
3 | | -from pathlib import Path |
| 3 | +from typing import TYPE_CHECKING |
4 | 4 |
|
5 | | -from mergecal import calendars_from_ical, merge_calendars |
| 5 | +import pytest |
6 | 6 |
|
7 | | -CALENDARS_DIR = Path(__file__).parent / "calendars" |
8 | | -TWO_VCALENDARS_DATA = (CALENDARS_DIR / "two_vcalendars.ics").read_bytes() |
| 7 | +from mergecal import merge_calendars |
9 | 8 |
|
| 9 | +if TYPE_CHECKING: |
| 10 | + from icalendar import Calendar |
10 | 11 |
|
11 | | -def test_calendars_from_ical_returns_two_calendars() -> None: |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def two_vcalendars_cals(calendars) -> list["Calendar"]: |
| 15 | + """Fixture providing parsed calendars from two_vcalendars.ics file.""" |
| 16 | + return calendars.two_vcalendars.stream |
| 17 | + |
| 18 | + |
| 19 | +def test_calendars_from_ical_returns_two_calendars( |
| 20 | + two_vcalendars_cals: list["Calendar"], |
| 21 | +) -> None: |
12 | 22 | """Parse an ICS file with two VCALENDAR blocks and get two Calendar objects.""" |
13 | | - cals = calendars_from_ical(TWO_VCALENDARS_DATA) |
14 | | - assert len(cals) == 2 |
| 23 | + assert len(two_vcalendars_cals) == 2 |
15 | 24 |
|
16 | 25 |
|
17 | | -def test_merge_file_with_two_vcalendars_yields_both_events() -> None: |
| 26 | +def test_merge_file_with_two_vcalendars_yields_both_events( |
| 27 | + two_vcalendars_cals: list["Calendar"], |
| 28 | +) -> None: |
18 | 29 | """Merging calendars from a multi-VCALENDAR file produces all events.""" |
19 | | - cals = calendars_from_ical(TWO_VCALENDARS_DATA) |
20 | | - merged = merge_calendars(cals) |
| 30 | + merged = merge_calendars(two_vcalendars_cals) |
21 | 31 | summaries = {str(e.get("summary")) for e in merged.walk("VEVENT")} |
22 | 32 | assert summaries == {"Event A", "Event B"} |
23 | 33 |
|
24 | 34 |
|
25 | | -def test_merging_multi_vcalendar_file_with_itself_deduplicates() -> None: |
| 35 | +def test_merging_multi_vcalendar_file_with_itself_deduplicates( |
| 36 | + two_vcalendars_cals: list["Calendar"], |
| 37 | +) -> None: |
26 | 38 | """Merging a multi-VCALENDAR file with itself produces no duplicate events.""" |
27 | | - cals = calendars_from_ical(TWO_VCALENDARS_DATA) |
| 39 | + cals = two_vcalendars_cals |
28 | 40 | merged_once = merge_calendars(cals) |
29 | 41 | merged_twice = merge_calendars(cals + cals) |
30 | 42 | assert merged_once == merged_twice |
|
0 commit comments