File: test_timezone_compat.py

package info (click to toggle)
python-ical 12.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,776 kB
  • sloc: python: 15,157; sh: 9; makefile: 5
file content (58 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Tests for the extended timezone component."""

import pathlib

import pytest
from syrupy import SnapshotAssertion

from ical.exceptions import CalendarParseError
from ical.calendar_stream import CalendarStream, IcsCalendarStream
from ical.store import TodoStore
from ical.compat import timezone_compat

TESTDATA_PATH = pathlib.Path("tests/compat/testdata/")
OFFICE_365_EXTENDED_TIMEZONE = TESTDATA_PATH / "office_365_extended_timezone.ics"
OFFICE_365_INVALID_TIMEZONE = TESTDATA_PATH / "office_365_invalid_timezone.ics"


def test_extended_timezone_fail() -> None:
    """Test Office 365 extended timezone."""

    with pytest.raises(
        CalendarParseError,
        match="Expected DATE-TIME TZID value 'W. Europe Standard Time' to be valid timezone",
    ):
        IcsCalendarStream.calendar_from_ics(
            OFFICE_365_EXTENDED_TIMEZONE.read_text(encoding="utf-8")
        )


def test_extended_timezone_compat(snapshot: SnapshotAssertion) -> None:
    """Test Office 365 extended timezone with compat enabled."""
    with timezone_compat.enable_extended_timezones():
        calendar = IcsCalendarStream.calendar_from_ics(
            OFFICE_365_EXTENDED_TIMEZONE.read_text(encoding="utf-8")
        )
    assert IcsCalendarStream.calendar_to_ics(calendar) == snapshot


def test_invalid_timezone_fail() -> None:
    """Test Office 365 invalid timezone."""

    with pytest.raises(
        CalendarParseError,
        match="Expected DATE-TIME TZID value 'Customized Time Zone' to be valid timezone",
    ):
        IcsCalendarStream.calendar_from_ics(
            OFFICE_365_INVALID_TIMEZONE.read_text(encoding="utf-8")
        )


def test_invalid_timezone_compat(snapshot: SnapshotAssertion) -> None:
    """Test Office 365 invalid timezone."""

    with timezone_compat.enable_allow_invalid_timezones():
        calendar = IcsCalendarStream.calendar_from_ics(
            OFFICE_365_INVALID_TIMEZONE.read_text(encoding="utf-8")
        )
    assert IcsCalendarStream.calendar_to_ics(calendar) == snapshot