Skip to content

Commit

Permalink
Merge pull request #602 from niccokunzmann/refactor-test-6
Browse files Browse the repository at this point in the history
Refactor calendar tests
  • Loading branch information
jacadzaca committed Mar 18, 2024
2 parents b51fef6 + a59ce3c commit f417720
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 405 deletions.
21 changes: 21 additions & 0 deletions src/icalendar/tests/calendars/parsing_error.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DESCRIPTION:Perfectly OK event
DTSTART;VALUE=DATE:20080303
DTEND;VALUE=DATE:20080304
RRULE:FREQ=DAILY;UNTIL=20080323T235959Z
EXDATE;VALUE=DATE:20080311
END:VEVENT
BEGIN:VEVENT
DESCRIPTION:Wrong event
DTSTART;VALUE=DATE:20080303
DTEND;VALUE=DATE:20080304
RRULE:FREQ=DAILY;UNTIL=20080323T235959Z
EXDATE;VALUE=DATE:20080311
EXDATE;VALUE=DATE:
END:VEVENT
END:VCALENDAR
11 changes: 11 additions & 0 deletions src/icalendar/tests/calendars/parsing_error_in_UTC_offset.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BEGIN:VCALENDAR
BEGIN:VTIMEZONE
TZID:Europe/Prague
BEGIN:STANDARD
DTSTART:18500101T000000
TZNAME:PMT
TZOFFSETFROM:+5744
TZOFFSETTO:+5744
END:STANDARD
END:VTIMEZONE
END:VCALENDAR
59 changes: 58 additions & 1 deletion src/icalendar/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import zoneinfo
except ModuleNotFoundError:
from backports import zoneinfo
from icalendar.cal import Component, Calendar, Event, ComponentFactory


class DataSource:
'''A collection of parsed ICS elements (e.g calendars, timezones, events)'''
Expand Down Expand Up @@ -88,7 +90,8 @@ def in_timezone(request):
for key in data.keys() if key not in
( # exclude broken calendars here
"big_bad_calendar", "issue_104_broken_calendar", "small_bad_calendar",
"multiple_calendar_components", "pr_480_summary_with_colon"
"multiple_calendar_components", "pr_480_summary_with_colon",
"parsing_error_in_UTC_offset", "parsing_error",
)
]
@pytest.fixture(params=ICS_FILES)
Expand All @@ -104,3 +107,57 @@ def ics_file(request):
def fuzz_v1_calendar(request):
"""Clusterfuzz calendars."""
return request.param


@pytest.fixture()
def factory():
"""Return a new component factory."""
return icalendar.ComponentFactory()


@pytest.fixture()
def vUTCOffset_ignore_exceptions():
icalendar.vUTCOffset.ignore_exceptions = True
yield
icalendar.vUTCOffset.ignore_exceptions = False


@pytest.fixture()
def event_component():
"""Return an event component."""
c = Component()
c.name = 'VEVENT'
return c


@pytest.fixture()
def c():
"""Return an empty component."""
c = Component()
return c
comp = c

@pytest.fixture()
def calendar_component():
"""Return an empty component."""
c = Component()
c.name = 'VCALENDAR'
return c


@pytest.fixture()
def filled_event_component(c, calendar_component):
"""Return an event with some values and add it to calendar_component."""
e = Component(summary='A brief history of time')
e.name = 'VEVENT'
e.add('dtend', '20000102T000000', encode=0)
e.add('dtstart', '20000101T000000', encode=0)
calendar_component.add_component(e)
return e


@pytest.fixture()
def calendar_with_resources():
c = Calendar()
c['resources'] = 'Chair, Table, "Room: 42"'
return c

0 comments on commit f417720

Please sign in to comment.