kopia lustrzana https://github.com/collective/icalendar
Compare test calendars to find components that do not equal
rodzic
da887c1f87
commit
2ae03ec4bf
|
@ -4,4 +4,5 @@ SUMMARY:Example calendar with a ': ' in the summary
|
|||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:Another event with a ': ' in the summary
|
||||
END:VEVENT
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
|
|
|
@ -15,6 +15,10 @@ class DataSource:
|
|||
self._parser = parser
|
||||
self._data_source_folder = data_source_folder
|
||||
|
||||
def keys(self):
|
||||
"""Return all the files that could be used."""
|
||||
return [file[:-4] for file in os.listdir(self._data_source_folder) if file.lower().endswith(".ics")]
|
||||
|
||||
def __getattr__(self, attribute):
|
||||
"""Parse a file and return the result stored in the attribute."""
|
||||
source_file = attribute.replace('-', '_') + '.ics'
|
||||
|
@ -40,20 +44,23 @@ class DataSource:
|
|||
|
||||
HERE = os.path.dirname(__file__)
|
||||
CALENDARS_FOLDER = os.path.join(HERE, 'calendars')
|
||||
CALENDARS = DataSource(CALENDARS_FOLDER, icalendar.Calendar.from_ical)
|
||||
TIMEZONES_FOLDER = os.path.join(HERE, 'timezones')
|
||||
TIMEZONES = DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical)
|
||||
EVENTS_FOLDER = os.path.join(HERE, 'events')
|
||||
EVENTS = DataSource(EVENTS_FOLDER, icalendar.Event.from_ical)
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def calendars():
|
||||
return DataSource(CALENDARS_FOLDER, icalendar.Calendar.from_ical)
|
||||
return CALENDARS
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def timezones():
|
||||
return DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical)
|
||||
return TIMEZONES
|
||||
|
||||
@pytest.fixture
|
||||
@pytest.fixture()
|
||||
def events():
|
||||
return DataSource(EVENTS_FOLDER, icalendar.Event.from_ical)
|
||||
return EVENTS
|
||||
|
||||
@pytest.fixture(params=[
|
||||
pytz.utc,
|
||||
|
@ -71,3 +78,18 @@ def utc(request):
|
|||
])
|
||||
def in_timezone(request):
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=[
|
||||
(data, key)
|
||||
for data in [CALENDARS, TIMEZONES, EVENTS]
|
||||
for key in data.keys() if key not in
|
||||
(
|
||||
"big_bad_calendar", "issue_104_broken_calendar", "small_bad_calendar",
|
||||
"multiple_calendar_components")
|
||||
])
|
||||
def ics_file(request):
|
||||
"""An example ICS file."""
|
||||
data, key = request.param
|
||||
print(key)
|
||||
return data[key]
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
'''tests ensuring that *the* way of doing things works'''
|
||||
|
||||
import datetime
|
||||
|
||||
from icalendar import Calendar, Event
|
||||
|
||||
import pytest
|
||||
import copy
|
||||
|
||||
def test_creating_calendar_with_unicode_fields(calendars, utc):
|
||||
''' create a calendar with events that contain unicode characters in their fields '''
|
||||
|
@ -39,3 +38,16 @@ def test_creating_calendar_with_unicode_fields(calendars, utc):
|
|||
|
||||
assert cal.to_ical() == calendars.created_calendar_with_unicode_fields.raw_ics
|
||||
|
||||
|
||||
def test_parsed_calendars_are_equal(ics_file):
|
||||
"""Ensure that a calendar equals the same calendar."""
|
||||
copy_of_calendar = ics_file.__class__.from_ical(ics_file.to_ical())
|
||||
assert copy_of_calendar == ics_file
|
||||
|
||||
def test_copies_are_equal(ics_file):
|
||||
"""Ensure that copies are equal."""
|
||||
assert ics_file.copy() == ics_file.copy() == ics_file
|
||||
|
||||
def test_deep_copies_are_equal(ics_file):
|
||||
"""Ensure that deep copies are equal."""
|
||||
assert copy.deepcopy(ics_file) == copy.deepcopy(ics_file) == ics_file
|
||||
|
|
Ładowanie…
Reference in New Issue