Debian Codegraph @

recurring_ical_events/test/test_time_zones_differ.py

raw symbols SCIP
1 """Imputs of different time zones should make a difference in the output"""
2
3 import datetime
4
5 import pytest
6 import pytz
7
8
9 @pytest.mark.parametrize(
10 ("date", "hours", "timezone", "number_of_events", "calendar_name"),
11 [
12 # DTSTART;TZID=Europe/Berlin:20190304T000000
13 # time zone offset 6:07:00 between Europe/Berlin and Asia/Ho_Chi_Minh
14 ((2019, 3, 4), 24, "Europe/Berlin", 1, "three_events"),
15 ((2019, 3, 4), 24, "America/Panama", 0, "three_events"),
16 ((2019, 3, 4), 24, "Asia/Ho_Chi_Minh", 1, "three_events"),
17 ((2019, 3, 4), 1, "Asia/Ho_Chi_Minh", 0, "three_events"),
18 ((2019, 3, 4), 6, "Asia/Ho_Chi_Minh", 0, "three_events"),
19 ((2019, 3, 4), 7, "Asia/Ho_Chi_Minh", 1, "three_events"),
20 # events that have no time zone, New Year
21 ((2019, 1, 1), 1, "Europe/Berlin", 1, "Germany"),
22 ((2019, 1, 1), 1, "Asia/Ho_Chi_Minh", 1, "Germany"),
23 ((2019, 1, 1), 1, "America/Panama", 1, "Germany"),
24 ],
25 )
26 def test_include_events_if_the_time_zone_differs(
27 calendars, date, hours, timezone, number_of_events, calendar_name
28 ):
29 """When the time zone is different, events can be included or
30 excluded because they are in another time zone.
31 """
32 tzinfo = pytz.timezone(timezone)
33 start = tzinfo.localize(datetime.datetime(*date))
34 stop = start + datetime.timedelta(hours=hours)
35 events = calendars[calendar_name].between(start, stop)
36 assert len(events) == number_of_events, (
37 f"in calendar {calendar_name} and {date} in {timezone}"
38 )