kopia lustrzana https://github.com/collective/icalendar
refactor test_issue_237
rodzic
6e78ab6a3b
commit
77a9bf4ba9
|
@ -0,0 +1,23 @@
|
|||
BEGIN:VCALENDAR
|
||||
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
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID="(UTC-03:00) Brasília":20170511T133000
|
||||
DTEND;TZID="(UTC-03:00) Brasília":20170511T140000
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
|
@ -4,6 +4,14 @@ import logging
|
|||
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:
|
||||
|
@ -30,9 +38,14 @@ class DataSource:
|
|||
return repr(self.__dict__)
|
||||
|
||||
HERE = os.path.dirname(__file__)
|
||||
CALENDARS_FOLDER = os.path.join(HERE, 'calendars')
|
||||
TIMEZONES_FOLDER = os.path.join(HERE, 'timezones')
|
||||
EVENTS_FOLDER = os.path.join(HERE, 'events')
|
||||
|
||||
@pytest.fixture
|
||||
def calendars():
|
||||
return DataSource(CALENDARS_FOLDER, icalendar.Calendar.from_ical)
|
||||
|
||||
@pytest.fixture
|
||||
def timezones():
|
||||
return DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical)
|
||||
|
@ -41,3 +54,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
|
||||
|
|
|
@ -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 @@ class TestEncoding(unittest.TestCase):
|
|||
+ 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(calendars, timezone):
|
||||
"""Issue #237 - Fail to parse timezone with non-ascii TZID
|
||||
see https://github.com/collective/icalendar/issues/237
|
||||
"""
|
||||
start = calendars.issue_237_fail_to_parse_timezone_with_non_ascii_tzid.walk('VEVENT')[0].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}'
|
||||
|
||||
|
|
|
@ -438,50 +438,6 @@ END:VCALENDAR"""
|
|||
b'END:VEVENT\r\n'
|
||||
)
|
||||
|
||||
def test_issue_237(self):
|
||||
"""Issue #237 - Fail to parse timezone with non-ascii TZID"""
|
||||
|
||||
ical_str = ['BEGIN:VCALENDAR',
|
||||
'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',
|
||||
'BEGIN:VEVENT',
|
||||
'DTSTART;TZID=\"(UTC-03:00) Brasília\":20170511T133000',
|
||||
'DTEND;TZID=\"(UTC-03:00) Brasília\":20170511T140000',
|
||||
'END:VEVENT',
|
||||
'END:VCALENDAR',
|
||||
]
|
||||
|
||||
cal = icalendar.Calendar.from_ical('\r\n'.join(ical_str))
|
||||
self.assertEqual(cal.errors, [])
|
||||
|
||||
dtstart = cal.walk(name='VEVENT')[0].decoded("DTSTART")
|
||||
expected = pytz.timezone('America/Sao_Paulo').localize(datetime.datetime(2017, 5, 11, 13, 30))
|
||||
self.assertEqual(dtstart, expected)
|
||||
|
||||
try:
|
||||
expected_zone = '(UTC-03:00) Brasília'
|
||||
expected_tzname = 'Brasília standard'
|
||||
except UnicodeEncodeError:
|
||||
expected_zone = '(UTC-03:00) Brasília'.encode('ascii', 'replace')
|
||||
expected_tzname = 'Brasília standard'.encode('ascii', 'replace')
|
||||
self.assertEqual(dtstart.tzinfo.zone, expected_zone)
|
||||
self.assertEqual(dtstart.tzname(), expected_tzname)
|
||||
|
||||
def test_issue_345(self):
|
||||
"""Issue #345 - Why is tools.UIDGenerator a class (that must be instantiated) instead of a module? """
|
||||
uid1 = icalendar.tools.UIDGenerator.uid()
|
||||
|
|
|
@ -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
|
Ładowanie…
Reference in New Issue