Skip to content

Commit

Permalink
do not copy() subcomponents
Browse files Browse the repository at this point in the history
  • Loading branch information
niccokunzmann committed Nov 1, 2023
1 parent ec8d604 commit 7add097
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
6 changes: 0 additions & 6 deletions src/icalendar/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,6 @@ def __eq__(self, other):

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

Expand Down
38 changes: 18 additions & 20 deletions src/icalendar/tests/test_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,28 @@ def test_parsed_calendars_are_equal_if_parsed_again(ics_file):

def test_parsed_calendars_are_equal_if_from_same_source(ics_file):
"""Ensure that a calendar equals the same calendar."""
same_calendar = ics_file.__class__.from_ical(ics_file.raw_ics)
assert same_calendar == ics_file
assert not same_calendar != ics_file
cal1 = ics_file.__class__.from_ical(ics_file.raw_ics)
cal2 = ics_file.__class__.from_ical(ics_file.raw_ics)
assert cal1 == cal2
assert not cal1 != cal2


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
copy1 = ics_file.copy(); copy1.subcomponents = ics_file.subcomponents
copy2 = ics_file.copy(); copy2.subcomponents = ics_file.subcomponents[:]
assert copy1 == copy2
assert copy1 == ics_file
assert copy2 == ics_file
assert not copy1 != copy2
assert not copy1 != ics_file
assert not copy2 != ics_file


def test_copy_does_not_copy_subcomponents(calendars):
"""If we copy the subcomponents, assumptions around copies will be broken."""
assert calendars.timezoned.subcomponents
assert not calendars.timezoned.copy().subcomponents


def test_deep_copies_are_equal(ics_file):
Expand All @@ -41,19 +52,6 @@ def test_deep_copies_are_equal(ics_file):
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


def test_vGeo():
"""Check the equality of vGeo."""
assert vGeo(("100", "12.33")) == vGeo(("100.00", "12.330"))
Expand Down

0 comments on commit 7add097

Please sign in to comment.