forked from ics-py/ics-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage for Event class by 10% (ics-py#346)
Co-authored-by: 0xC4 <[email protected]>
- Loading branch information
1 parent
bc19f7f
commit b1996f4
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from datetime import date, datetime, timedelta | ||
|
||
import pytest | ||
|
||
from ics import Calendar, Event, Timezone, Todo | ||
from ics.event import deterministic_event_data | ||
from ics.timezone import UTC | ||
|
||
SUMMARY = "test summary" | ||
|
||
@deterministic_event_data() | ||
@pytest.mark.parametrize( | ||
"begin,end,duration", | ||
[ | ||
( | ||
datetime.fromisoformat("2022-09-16 12:00"), | ||
datetime.fromisoformat("2022-09-16 12:30"), | ||
timedelta(minutes=30), | ||
), | ||
( | ||
date.fromisoformat("2022-09-16"), | ||
date.fromisoformat("2022-09-17"), | ||
timedelta(hours=24), | ||
), | ||
( | ||
datetime.fromisoformat("2022-09-16 06:00"), | ||
datetime.fromisoformat("2022-09-17 08:30"), | ||
timedelta(days=1, hours=2, minutes=30), | ||
), | ||
], | ||
) | ||
def test_duration(begin: datetime, end: datetime, duration: timedelta) -> None: | ||
event = Event(SUMMARY, begin, end) | ||
assert event.duration == duration | ||
|
||
|
||
@deterministic_event_data() | ||
def test_comparisons() -> None: | ||
event1 = Event(SUMMARY, date(2022, 9, 6), date(2022, 9, 7)) | ||
event2 = Event(SUMMARY, date(2022, 9, 8), date(2022, 9, 10)) | ||
assert event1 < event2 | ||
assert event1 <= event2 | ||
assert event2 >= event1 | ||
assert event2 > event1 | ||
|
||
|
||
@deterministic_event_data() | ||
def test_within_and_includes() -> None: | ||
event1 = Event(SUMMARY, date(2022, 9, 6), date(2022, 9, 10)) | ||
event2 = Event(SUMMARY, date(2022, 9, 7), date(2022, 9, 8)) | ||
event3 = Event(SUMMARY, date(2022, 9, 9), date(2022, 9, 11)) | ||
|
||
assert not event1.starts_within(event2) | ||
assert not event1.starts_within(event3) | ||
assert event2.starts_within(event1) | ||
assert not event2.starts_within(event3) | ||
assert event3.starts_within(event1) | ||
assert not event3.starts_within(event2) | ||
|
||
assert not event1.ends_within(event2) | ||
assert event1.ends_within(event3) | ||
assert event2.ends_within(event1) | ||
assert not event2.ends_within(event3) | ||
assert not event3.ends_within(event1) | ||
assert not event3.ends_within(event2) | ||
assert event2 > event1 | ||
|
||
assert event1.includes(event2) | ||
assert not event1.includes(event3) | ||
assert not event2.includes(event1) | ||
assert not event2.includes(event3) | ||
assert not event3.includes(event1) | ||
assert not event3.includes(event2) | ||
|
||
assert not event1.is_included_in(event2) | ||
assert not event1.is_included_in(event3) | ||
assert event2.is_included_in(event1) | ||
assert not event2.is_included_in(event3) | ||
assert not event3.is_included_in(event1) | ||
assert not event3.is_included_in(event2) | ||
|
||
|
||
@deterministic_event_data() | ||
@pytest.mark.parametrize( | ||
"event1,event2,expect_intersects", | ||
[ | ||
( | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 16), | ||
date(2022, 9, 17), | ||
), | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 18), | ||
date(2022, 9, 19), | ||
), | ||
False, | ||
), | ||
( | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 16), | ||
date(2022, 9, 19), | ||
), | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 17), | ||
date(2022, 9, 18), | ||
), | ||
True, | ||
), | ||
( | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 16), | ||
date(2022, 9, 18), | ||
), | ||
Event( | ||
SUMMARY, | ||
date(2022, 9, 17), | ||
date(2022, 9, 19), | ||
), | ||
True, | ||
), | ||
], | ||
) | ||
def test_intersects(event1: Event, event2: Event, expect_intersects: bool) -> None: | ||
assert event2.intersects(event1) == expect_intersects | ||
|
||
|
||
|