Skip to content

Commit

Permalink
refactor issue 273
Browse files Browse the repository at this point in the history
  • Loading branch information
jacadzaca committed Sep 20, 2022
1 parent 84b2c7b commit 577d233
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/icalendar/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -47,3 +55,6 @@ def calendars():
def calendars_folder():
return CALENDARS_FOLDER

@pytest.fixture(params=[pytz.timezone, tz.gettz, zoneinfo.ZoneInfo])
def timezone(request):
return request.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN:VEVENT
DTSTART;TZID="(UTC-03:00) Brasília":20170511T133000
DTEND;TZID="(UTC-03:00) Brasília":20170511T140000
END:VEVENT

27 changes: 27 additions & 0 deletions src/icalendar/tests/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import icalendar
import os
import pytz
from dateutil import tz

try:
import zoneinfo
except ModuleNotFoundError:
from backports import zoneinfo


class TestEncoding(unittest.TestCase):
Expand Down Expand Up @@ -109,3 +115,24 @@ def test_events_unicoded(events, event_name):
event = getattr(events, event_name)
assert event.to_ical() == event.raw_ics

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}'

17 changes: 17 additions & 0 deletions src/icalendar/tests/timezones/issue_237_brazilia_standard.ics
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 577d233

Please sign in to comment.