Skip to content

Commit

Permalink
compare vTime and add more tests for equality
Browse files Browse the repository at this point in the history
  • Loading branch information
niccokunzmann committed Nov 1, 2023
1 parent 6274d88 commit d95007b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/icalendar/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def __repr__(self):
return f"{self.name or type(self).__name__}({dict(self)}{', ' + subs if subs else ''})"

def __eq__(self, other):
if not len(self.subcomponents) == len(other.subcomponents):
if len(self.subcomponents) != len(other.subcomponents):
return False

properties_equal = super().__eq__(other)
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def from_ical(cls, ical):
return cls(ical_unesc)


class vTime:
class vTime(DtEqualityMixin):
"""Render and generates iCalendar time format.
"""

Expand Down
18 changes: 17 additions & 1 deletion src/icalendar/tests/test_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@
import pytest


def test_parsed_calendars_are_equal(ics_file):
def test_parsed_calendars_are_equal_if_parsed_again(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_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


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:
Expand Down Expand Up @@ -68,6 +76,13 @@ def test_vCategory():
assert vCategory(["a","b"]) != vCategory(["a","b", "c"])


def test_vText():
assert vText("HELLO") == vText("HELLO")
assert not vText("HELLO") != vText("HELLO")
assert vText("HELLO1") != vText("HELLO")
assert not vText("HELLO1") == vText("HELLO")


@pytest.mark.parametrize(
"vType,v1,v2",
[
Expand All @@ -77,6 +92,7 @@ def test_vCategory():
(vPeriod, (datetime(2023, 11, 1, 10, 11), timedelta(3, 11, 1)), (datetime(2023, 11, 1, 10, 11), timedelta(23, 10, 31))),
(vPeriod, (datetime(2023, 11, 1, 10, 1), timedelta(3, 11, 1)), (datetime(2023, 11, 1, 10, 11), timedelta(3, 11, 1))),
(vPeriod, (datetime(2023, 11, 1, 10, 1), datetime(2023, 11, 1, 10, 3)), (datetime(2023, 11, 1, 10, 1), datetime(2023, 11, 1, 10, 2))),
(vTime, time(10, 10, 10), time(10, 10, 11)),
]
)
@pytest.mark.parametrize("eq", ["==", "!="])
Expand Down

0 comments on commit d95007b

Please sign in to comment.