Debian Codegraph @

recurring_ical_events/test/test_x_wr_timezone.py

raw symbols SCIP
1 """These test the support of the non-standard X-WR-TIMEZONE attribute.
2
3 See Issue 71: https://github.com/niccokunzmann/python-recurring-ical-events/issues/71
4 """
5
6 import datetime
7
8 import pytest
9 from pytz import UTC, timezone
10
11 from recurring_ical_events.util import timestamp
12
13 tz_london = timezone("Europe/London")
14
15 c1_t_utc = UTC.localize(datetime.datetime(2013, 8, 3, 19))
16 c1_t_london = tz_london.localize(datetime.datetime(2013, 8, 3, 20))
17
18 hour_1 = datetime.timedelta(hours=1)
19 hour_2 = hour_1 + hour_1
20
21
22 def test_dates_are_equal():
23 """These dates need to be equal so that the next test 'test_events_with_x_wr_timezone_returned()' works."""
24 t1 = timestamp(c1_t_utc)
25 t2 = timestamp(c1_t_london)
26 assert t1 == t2, f"time stamp should equal, delta {t1 - t2}"
27 assert c1_t_utc == c1_t_london, "dates should equal"
28
29
30 c1 = "rdate_hackerpublicradio"
31 c2 = "x_wr_timezone_simple_events_issue_59"
32
33
34 @pytest.mark.parametrize(
35 ("calendar_name", "a_date", "event_count", "message"),
36 [
37 # test c1
38 # Europe/London changes into summer time after March to October.
39 # We test with UTC as time zone
40 (c1, c1_t_utc, 1, "(1) Exact start of the first event."),
41 (c1, c1_t_utc + hour_1, 1, "(1) Middle of the first event."),
42 (c1, c1_t_utc + hour_2, 0, "(1) Exact end of the first event."),
43 # Other time zone as argument
44 (c1, c1_t_london, 1, "(2) Exact start of the first event. (London)"),
45 (c1, c1_t_london + hour_1, 1, "(2) Middle of the first event. (London)"),
46 (c1, c1_t_london + hour_2, 0, "(2) Exact end of the first event. (London)"),
47 # test c2
48 # here, we have the dates and times of the events given
49 # test the first event
50 (c2, (2021, 12, 22, 12, 0), 1, "(3) Exact start of the event. New York"),
51 (c2, (2021, 12, 22, 11, 59), 0, "(3) Before the event. New York"),
52 (c2, (2021, 12, 22, 12, 59), 1, "(3) Event almost over. New York"),
53 (c2, (2021, 12, 22, 13, 0), 0, "(3) After the event. New York"),
54 # second event
55 (c2, (2021, 12, 22, 21), 1, "(4) Exact start of the event. New York"),
56 (c2, (2021, 12, 22, 20, 59), 0, "(4) Before the event. New York"),
57 (c2, (2021, 12, 22, 21, 59), 1, "(4) Event almost over. New York"),
58 (c2, (2021, 12, 22, 22), 0, "(4) After the event. New York"),
59 ],
60 )
61 def test_events_with_x_wr_timezone_returned(
62 calendars, calendar_name, a_date, event_count, message
63 ):
64 """Test that X-WR-TIMEZONE influences the event results."""
65 calendar = calendars[calendar_name]
66 for e in calendar.all():
67 print(e.to_ical().decode("UTF-8"))
68 events = calendar.at(a_date)
69 assert len(events) == event_count, message