From 2694cb2eceabb1781fccacab8aba410d4b24e52e Mon Sep 17 00:00:00 2001 From: jaca Date: Tue, 20 Sep 2022 14:38:41 +0200 Subject: [PATCH] refacotr test_issue_237 --- src/icalendar/tests/conftest.py | 11 ++++++++ ..._to_parse_timezone_with_non_ascii_tzid.ics | 5 ++++ src/icalendar/tests/test_encoding.py | 25 ++++++++++++++++++- .../timezones/issue_237_brazilia_standard.ics | 17 +++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/icalendar/tests/events/issue_237_fail_to_parse_timezone_with_non_ascii_tzid.ics create mode 100644 src/icalendar/tests/timezones/issue_237_brazilia_standard.ics diff --git a/src/icalendar/tests/conftest.py b/src/icalendar/tests/conftest.py index 838c506d..986f2ff9 100644 --- a/src/icalendar/tests/conftest.py +++ b/src/icalendar/tests/conftest.py @@ -4,6 +4,14 @@ import pytest import icalendar +import datetime +import pytz +from dateutil import tz +try: + import zoneinfo +except ModuleNotFoundError: + from backports import zoneinfo + LOGGER = logging.getLogger(__name__) class DataSource: @@ -41,3 +49,6 @@ def timezones(): def events(): return DataSource(EVENTS_FOLDER, icalendar.Event.from_ical) +@pytest.fixture(params=[pytz.timezone, tz.gettz, zoneinfo.ZoneInfo]) +def timezone(request): + return request.param diff --git a/src/icalendar/tests/events/issue_237_fail_to_parse_timezone_with_non_ascii_tzid.ics b/src/icalendar/tests/events/issue_237_fail_to_parse_timezone_with_non_ascii_tzid.ics new file mode 100644 index 00000000..4aef22dc --- /dev/null +++ b/src/icalendar/tests/events/issue_237_fail_to_parse_timezone_with_non_ascii_tzid.ics @@ -0,0 +1,5 @@ +BEGIN:VEVENT +DTSTART;TZID="(UTC-03:00) Brasília":20170511T133000 +DTEND;TZID="(UTC-03:00) Brasília":20170511T140000 +END:VEVENT + diff --git a/src/icalendar/tests/test_encoding.py b/src/icalendar/tests/test_encoding.py index d1d70d37..a06bb769 100644 --- a/src/icalendar/tests/test_encoding.py +++ b/src/icalendar/tests/test_encoding.py @@ -1,11 +1,12 @@ import unittest +import pytest + import datetime import icalendar import os import pytz - class TestEncoding(unittest.TestCase): def test_create_from_ical(self): @@ -88,3 +89,25 @@ def test_unicode_parameter_name(self): + b'\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\xc3\x84\xc3\x96\xc3\x9c\r\n' + b'END:VEVENT\r\nEND:VCALENDAR\r\n' ) + +def test_parses_event_with_non_ascii_tzid_issue_237(events, timezone): + """Issue #237 - Fail to parse timezone with non-ascii TZID + see https://github.com/collective/icalendar/issues/237 + """ + start = events.issue_237_fail_to_parse_timezone_with_non_ascii_tzid.decoded('DTSTART') + expected = datetime.datetime(2017, 5, 11, 13, 30, tzinfo=timezone('America/Sao_Paulo')) + assert start == expected + +def test_parses_timezone_with_non_ascii_tzid_issue_237(timezones): + """Issue #237 - Fail to parse timezone with non-ascii TZID + see https://github.com/collective/icalendar/issues/237 + """ + assert timezones.issue_237_brazilia_standard['tzid'] == '(UTC-03:00) Brasília' + +@pytest.mark.parametrize('timezone_name', ['standard', 'daylight']) +def test_parses_timezone_with_non_ascii_tzname_issue_273(timezones, timezone_name): + """Issue #237 - Fail to parse timezone with non-ascii TZID + see https://github.com/collective/icalendar/issues/237 + """ + assert timezones.issue_237_brazilia_standard.walk(timezone_name)[0]['TZNAME'] == f'Brasília {timezone_name}' + diff --git a/src/icalendar/tests/timezones/issue_237_brazilia_standard.ics b/src/icalendar/tests/timezones/issue_237_brazilia_standard.ics new file mode 100644 index 00000000..462f3fcd --- /dev/null +++ b/src/icalendar/tests/timezones/issue_237_brazilia_standard.ics @@ -0,0 +1,17 @@ +BEGIN:VTIMEZONE +TZID:(UTC-03:00) Brasília +BEGIN:STANDARD +TZNAME:Brasília standard +DTSTART:16010101T235959 +TZOFFSETFROM:-0200 +TZOFFSETTO:-0300 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=3SA;BYMONTH=2 +END:STANDARD +BEGIN:DAYLIGHT +TZNAME:Brasília daylight +DTSTART:16010101T235959 +TZOFFSETFROM:-0300 +TZOFFSETTO:-0200 +RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SA;BYMONTH=10 +END:DAYLIGHT +END:VTIMEZONE