Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/osekit/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def begin(self) -> Timestamp:

@begin.setter
def begin(self, value: Timestamp) -> None:
if hasattr(self, "_end") and value >= self._end:
if hasattr(self, "_end") and value > self._end:
msg = f"Invalid Event: `end` ({self._end}) must be greater than `begin` ({value})." # noqa: E501
raise ValueError(msg)
self._begin = value
Expand All @@ -49,7 +49,7 @@ def end(self) -> Timestamp:

@end.setter
def end(self, value: Timestamp) -> None:
if hasattr(self, "_begin") and value <= self._begin:
if hasattr(self, "_begin") and value < self._begin:
msg = f"Invalid Event: `end` ({value}) must be greater than `begin` ({self._begin})." # noqa: E501
raise ValueError(msg)
self._end = value
Expand Down
53 changes: 45 additions & 8 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from contextlib import nullcontext

import pytest
from pandas import Timestamp
from pandas import Timedelta, Timestamp

from osekit.core.event import Event

Expand Down Expand Up @@ -85,7 +85,7 @@
),
pytest.param(
Event(
begin=Timestamp("2024-01-01 0:00:00"),
begin=Timestamp("2024-01-01 00:00:00"),
end=Timestamp("2024-01-01 12:00:00"),
),
Event(
Expand All @@ -95,6 +95,18 @@
False,
id="border_sharing_isnt_overlapping",
),
pytest.param(
Event(
begin=Timestamp("2024-01-01 00:00:00"),
end=Timestamp("2024-01-01 00:00:00"),
),
Event(
begin=Timestamp("2024-01-01 00:00:00"),
end=Timestamp("2024-01-01 00:00:00"),
),
False,
id="instantaneous_events_dont_overlap",
),
],
)
def test_overlapping_events(
Expand Down Expand Up @@ -390,7 +402,12 @@ def test_get_overlapping_events(
),
Timestamp("2024-01-01 01:00:00"),
None,
pytest.raises(ValueError, match="`end`.*must be greater than `begin`.*"),
nullcontext(
Event(
begin=Timestamp("2024-01-01 01:00:00"),
end=Timestamp("2024-01-01 01:00:00"),
),
),
id="begin_equals_end",
),
],
Expand Down Expand Up @@ -424,11 +441,6 @@ def update_event(
Timestamp("2024-01-01 00:00:00"),
id="begin_after_end",
),
pytest.param(
Timestamp("2024-01-01 00:00:00"),
Timestamp("2024-01-01 00:00:00"),
id="begin_equals_end",
),
],
)
def test_event_errors(begin: Timestamp, end: Timestamp) -> None:
Expand All @@ -446,3 +458,28 @@ def test_repr() -> None:
)
== "1990-09-12 12:00:00 - 1990-09-12 12:00:10"
)


@pytest.mark.parametrize(
("event", "expected_duration"),
[
pytest.param(
Event(
begin=Timestamp("1990-09-12 12:00:00"),
end=Timestamp("1990-09-12 12:00:10"),
),
Timedelta(seconds=10),
id="non-instantaneous_event",
),
pytest.param(
Event(
begin=Timestamp("1990-09-12 12:00:10"),
end=Timestamp("1990-09-12 12:00:10"),
),
Timedelta(seconds=0),
id="instantaneous_event",
),
],
)
def test_duration(event: Event, expected_duration: Timedelta) -> None:
assert event.duration == expected_duration