kopia lustrzana https://github.com/collective/icalendar
Add test file for equality tests
rodzic
c9fbe223cb
commit
0eae8ceb04
|
@ -465,6 +465,11 @@ class Component(CaselessDict):
|
|||
|
||||
return True
|
||||
|
||||
def copy(self):
|
||||
"""Create a copy of the component."""
|
||||
copy = super().copy()
|
||||
copy.subcomponents = self.subcomponents[:]
|
||||
return copy
|
||||
|
||||
#######################################
|
||||
# components defined in RFC 5545
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
"""Test the equality and inequality of components."""
|
||||
import copy
|
||||
import pytz
|
||||
|
||||
|
||||
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
|
||||
assert not copy_of_calendar != ics_file
|
||||
|
||||
|
||||
def test_copies_are_equal(ics_file):
|
||||
"""Ensure that copies are equal."""
|
||||
assert ics_file.copy() == ics_file.copy()
|
||||
assert ics_file.copy() == ics_file
|
||||
assert not ics_file.copy() != ics_file.copy()
|
||||
assert not ics_file.copy() != ics_file
|
||||
|
||||
def test_deep_copies_are_equal(ics_file):
|
||||
"""Ensure that deep copies are equal."""
|
||||
try:
|
||||
assert copy.deepcopy(ics_file) == copy.deepcopy(ics_file)
|
||||
assert copy.deepcopy(ics_file) == ics_file
|
||||
assert not copy.deepcopy(ics_file) != copy.deepcopy(ics_file)
|
||||
assert not copy.deepcopy(ics_file) != ics_file
|
||||
except pytz.UnknownTimeZoneError:
|
||||
# Ignore errors when a custom time zone is used.
|
||||
# This is still covered by the parsing test.
|
||||
pass
|
||||
|
||||
|
||||
def test_a_components_copy_also_copies_subcomponents(calendars):
|
||||
"""A calendar's copy does not have the identical subcompoenets!
|
||||
|
||||
We expect to be able to modify a copy but not its values.
|
||||
"""
|
||||
cal = calendars.timezoned
|
||||
copy = cal.copy()
|
||||
assert copy is not cal
|
||||
assert copy.subcomponents
|
||||
assert copy.subcomponents is not cal.subcomponents
|
||||
assert copy.subcomponents == cal.subcomponents
|
|
@ -3,7 +3,7 @@
|
|||
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 '''
|
||||
|
@ -37,17 +37,3 @@ def test_creating_calendar_with_unicode_fields(calendars, utc):
|
|||
cal.add_component(event2)
|
||||
|
||||
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