Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_fixed_issues restructure #400

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/icalendar/tests/calendars/issue_104_broken_calendar.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BEGIN:VCALENDAR
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20140401T000000Z
DTEND:20140401T010000Z
DTSTAMP:20140401T000000Z
SUMMARY:Broken Eevnt
CLASS:PUBLIC
STATUS:CONFIRMED
TRANSP:OPAQUE
END:VEVENT
X
END:VCALENDAR
7 changes: 7 additions & 0 deletions src/icalendar/tests/calendars/issue_168_expected_output.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20150905T090000Z
DTEND:20150905T100000Z
UID:123
END:VEVENT
END:VCALENDAR
8 changes: 8 additions & 0 deletions src/icalendar/tests/calendars/issue_168_input.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
DTSTART:20150905T090000Z
DTEND:20150905T100000Z
UID:123
X-APPLE-RADIUS=49.91307046514149
END:VEVENT
END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BEGIN:MYCOMP
END:MYCOMP
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:MYCOMPTOO
DTSTAMP:20150121T080000
BEGIN:VEVENT
DTSTART:20150122
UID:12345
END:VEVENT
END:MYCOMPTOO
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN:VCALENDAR
BEGIN:UNKNOWN
UID:1234
END:UNKNOWN
END:VCALENDAR
60 changes: 60 additions & 0 deletions src/icalendar/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
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:
'''A collection of parsed ICS elements (e.g calendars, timezones, events)'''
def __init__(self, data_source_folder, parser):
for source_file in os.listdir(data_source_folder):
source_path = os.path.join(data_source_folder, source_file)
name = os.path.splitext(source_file)[0]
attribute_name = name.replace('-', '_')
with open(source_path, 'rb') as f:
try:
raw_ics = f.read()
source = parser(raw_ics)
source.raw_ics = raw_ics
setattr(self, attribute_name, source)
except ValueError as error:
LOGGER.error(f'Could not load {source_file} due to {error}')

HERE = os.path.dirname(__file__)
TIMEZONES_FOLDER = os.path.join(HERE, 'timezones')
EVENTS_FOLDER = os.path.join(HERE, 'events')
CALENDARS_FOLDER = os.path.join(HERE, 'calendars')

TIMEZONES = DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical)
EVENTS = DataSource(EVENTS_FOLDER, icalendar.Event.from_ical)
CALENDARS = DataSource(CALENDARS_FOLDER, icalendar.Calendar.from_ical)

@pytest.fixture
def timezones():
return TIMEZONES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, elements might be changed by tests and then, we have side effects.
Personally, I would put DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical) into the function body.

Does that impact execution time?

I would say that we can use __getattr__ to set the attributes and then, they will only loaded when needed. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@jacadzaca jacadzaca Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I didn't quite grasp the piece of code you've linked when I was writing my conftest. You're right that side effects are possible. I think implementing simple lazy loading shouldn't be too hard. I can override getattr or use the @property decorator, like you've said.


@pytest.fixture
def events():
return EVENTS

@pytest.fixture
def calendars():
return CALENDARS

@pytest.fixture
def calendars_folder():
return CALENDARS_FOLDER

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this file!

@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,3 @@
BEGIN:VEVENT
SUMMARY;LANGUAGE=ru:te
END:VEVENT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
BEGIN:VEVENT
SUMMARY:wichtiger termin 1
DTSTART:20130416T100000Z
DTEND:20130416T110000Z
DTSTAMP:20130416T092616Z
UID:20130416112341.10064jz0k4j7uem8@acmenet.de
CLASS:PUBLIC
CREATED:20130416T092341Z
LAST-MODIFIED:20130416T092341Z
LOCATION:im büro
ORGANIZER;CN="acme, ädmin":mailto:adm-acme@mydomain.de
STATUS:CONFIRMED
TRANSP:OPAQUE
END:VEVENT
10 changes: 10 additions & 0 deletions src/icalendar/tests/events/issue_104_mark_events_broken.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN:VEVENT
DTSTART:20140401T000000Z
DTEND:20140401T010000Z
DTSTAMP:20140401T000000Z
SUMMARY:Broken Eevnt
CLASS:PUBLIC
STATUS:CONFIRMED
TRANSP:OPAQUE
X
END:VEVENT
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is is removed is probably in the commit...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a trip up on my side, weird that the test still passes.

VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Market East
X-WR-TIMEZONE:America/New_York
X-WR-CALDESC:
BEGIN:VTIMEZONE
TZID:America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE

BEGIN:VEVENT
DTSTART;TZID=America/New_York:20130907T120000
DTEND;TZID=America/New_York:20130907T170000
Expand All @@ -45,4 +18,3 @@ SUMMARY:Market East Live!
TRANSP:OPAQUE
END:VEVENT

END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN:VEVENT
X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS="367 George Street Sydney
CBD NSW 2000";X-APPLE-RADIUS=72;X-TITLE="367 George Street":geo:-33.868900
\,151.207000
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BEGIN:VEVENT
DTSTART:20150325T101010
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU;
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN:VEVENT
DTSTART:20150219T133000
DTSTAMP:20150219T133000
UID:1234567
RDATE;VALUE=PERIOD:20150219T133000/PT10H
END:VEVENT
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN:VEVENT
DTSTAMP:20120605T003759Z
DTSTART;TZID=America/New_York:20120712T183000
DTEND;TZID=America/New_York:20120712T213000
STATUS:CONFIRMED
SUMMARY:DevOps DC Meetup
DESCRIPTION:DevOpsDC\nThursday\, July 12 at 6:30 PM\n\nThis will be a joi
nt meetup / hack night with the DC jQuery Users Group. The idea behind
the hack night: Small teams consisting of at least 1 member...\n\nDeta
ils: http://www.meetup.com/DevOpsDC/events/47635522/
CLASS:PUBLIC
CREATED:20120111T120339Z
GEO:38.90;-77.01
LOCATION:Fathom Creative\, Inc. (1333 14th Street Northwest\, Washington
D.C.\, DC 20005)
URL:http://www.meetup.com/DevOpsDC/events/47635522/
LAST-MODIFIED:20120522T174406Z
UID:event_qtkfrcyqkbnb@meetup.com
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN:VEVENT
SUMMARY:abcdef
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN:VEVENT
SUMMARY:åäö
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN:VEVENT
CREATED:20081114T072804Z
UID:D449CA84-00A3-4E55-83E1-34B58268853B
DTEND:20070220T180000
RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20070619T225959
TRANSP:OPAQUE
SUMMARY:Esb mellon phone conf
DTSTART:20070220T170000
DTSTAMP:20070221T095412Z
SEQUENCE:0
END:VEVENT

3 changes: 3 additions & 0 deletions src/icalendar/tests/events/issue_82_expected_output.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN:VEVENT
ATTACH;ENCODING=BASE64;FMTTYPE=text/plain;VALUE=BINARY:dGV4dA==
END:VEVENT
25 changes: 25 additions & 0 deletions src/icalendar/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'''Tests checking that *the* way of doing things works'''

from icalendar import Event


def test_adding_x_apple_structured_location_issue_116_117(events):
'''Issue #116/#117 - How to add 'X-APPLE-STRUCTURED-LOCATION'

https://github.com/collective/icalendar/issues/116
https://github.com/collective/icalendar/issues/117
'''
event = Event()
event.add(
'X-APPLE-STRUCTURED-LOCATION',
'geo:-33.868900,151.207000',
parameters={
'VALUE': 'URI',
'X-ADDRESS': '367 George Street Sydney CBD NSW 2000',
'X-APPLE-RADIUS': '72',
'X-TITLE': '367 George Street'
}
)

assert event.to_ical() == events.issue_116_117_add_x_apple_structured.raw_ics
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!


48 changes: 48 additions & 0 deletions src/icalendar/tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import unittest

import pytest

import datetime
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 @@ -88,3 +96,43 @@ 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'
)

@pytest.mark.parametrize('event_name', [
# Non-unicode characters in summary
'issue_64_event_with_non_unicode_summary',
# Unicode characters in summary
'issue_64_event_with_unicode_summary',
# chokes on umlauts in ORGANIZER
'issue_101_icalendar_chokes_on_umlauts_in_organizer'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Very clear which issue is referenced. This was important to me and it seems to work nicely.

])
def test_events_unicoded(events, event_name):
'''Issue #64 - Event.to_ical() fails for unicode strings
Issue #101 - icalendar is choking on umlauts in ORGANIZER

https://github.com/collective/icalendar/issues/64
https://github.com/collective/icalendar/issues/101
'''
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}'

Loading