Debian Codegraph @

recurring_ical_events/test/test_examples.py

raw symbols SCIP
1 import datetime
2
3 import pytest
4
5
6 def test_fablab_cottbus(calendars):
7 """This calendar threw an exception.
8
9 TypeError: can't compare offset-naive and offset-aware datetimes
10 """
11 today = datetime.datetime(2019, 3, 4, 16, 52, 10, 215209)
12 one_year_ahead = today.replace(year=today.year + 1)
13 one_year_before = today.replace(year=today.year - 1)
14 calendars.fablab_cottbus.between(one_year_before, one_year_ahead)
15
16
17 def test_example_from_README(calendars):
18 """The examples from the README should be tested so we make no
19 false promises.
20 """
21
22 start_date = (2019, 3, 5)
23 end_date = (2019, 4, 1)
24
25 events = calendars.one_day_event_repeat_every_day.between(start_date, end_date)
26 for event in events:
27 start = event["DTSTART"].dt
28 duration = event["DTEND"].dt - event["DTSTART"].dt
29 print(f"start {start} duration {duration}")
30 assert event
31
32
33 def test_no_dtend(calendars):
34 """This calendar has events which have no DTEND.
35
36 KeyError: 'DTEND'
37 """
38 list(calendars.discourse_no_dtend.all())
39
40
41 def test_date_events_are_in_the_date(calendars):
42 events = calendars.Germany.at((2014, 5, 11))
43 assert len(events) == 1
44 event = events[0]
45 assert event["SUMMARY"] == "Germany: Mother's Day [Not a public holiday]"
46 assert isinstance(event["DTSTART"].dt, datetime.date)
47
48
49 mb_on_tour_dates = [
50 (2018, 9, 22),
51 (2018, 10, 20),
52 (2018, 11, 17),
53 (2018, 12, 8),
54 (2019, 1, 12),
55 (2019, 1, 27),
56 (2019, 2, 9),
57 (2019, 2, 24),
58 (2019, 3, 23),
59 (2019, 4, 27),
60 (2019, 5, 25),
61 (2019, 6, 22),
62 ]
63
64
65 @pytest.mark.parametrize("date", mb_on_tour_dates)
66 def test_events_are_scheduled(calendars, date):
67 events = calendars.machbar_16_feb_2019.at(date)
68 assert len(events) == 1
69
70
71 @pytest.mark.parametrize(
72 "month",
73 [
74 (2018, 9),
75 (2018, 10),
76 (2018, 11),
77 (2018, 12),
78 (2019, 1),
79 (2019, 2),
80 (2019, 3),
81 (2019, 4),
82 (2019, 5),
83 (2019, 6),
84 (2019, 7),
85 ],
86 )
87 def test_no_more_events_are_scheduled(calendars, month):
88 dates = [date for date in mb_on_tour_dates if date[:2] == month]
89 number_of_dates = len(dates)
90 events = calendars.machbar_16_feb_2019.at(month)
91 mb_events = [event for event in events if "mB-onTour" in event["SUMMARY"]]
92 assert len(mb_events) == number_of_dates
93
94
95 def test_german_holidays(calendars):
96 """Test the calendar from
97 https://www.calendarlabs.com/ical-calendar/ics/46/Germany_Holidays.ics
98 """
99 holidays = calendars.Germany_Holidays.at(2020)
100 assert len(holidays) == 17
101
102
103 def test_exdate_date(calendars):
104 """The EXDATE can be a date, too.
105
106 See https://github.com/niccokunzmann/python-recurring-ical-events/pull/121
107 """
108 assert calendars.date_exclude.at("20231216") == []
109
110
111 @pytest.mark.parametrize(
112 ("date", "count"),
113 [
114 ("20240923", 0),
115 ("20240924", 3),
116 ("20240925", 0),
117 ("20240926", 3),
118 ("20240927", 0),
119 ],
120 )
121 def test_same_events_at_same_time(calendars, date, count):
122 """Make sure that events can be moved to the same time."""
123 assert len(calendars.same_event_recurring_at_same_time.at(date)) == count