snapshot of https://github.com/ActivityWatch/aw-core.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build / Test on ubuntu-latest, py-3.8 (push) Successful in 4m21s
Lint / lint (push) Successful in 25s
Build / Test on macOS-latest, py-3.8 (push) Has been cancelled
Build / Test on windows-latest, py-3.8 (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
Some checks failed
Build / Test on ubuntu-latest, py-3.8 (push) Successful in 4m21s
Lint / lint (push) Successful in 25s
Build / Test on macOS-latest, py-3.8 (push) Has been cancelled
Build / Test on windows-latest, py-3.8 (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
This commit is contained in:
41
tests/test_event.py
Normal file
41
tests/test_event.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from aw_core.models import Event
|
||||
|
||||
valid_timestamp = "1937-01-01T12:00:27.87+00:20"
|
||||
|
||||
now = datetime.now(timezone.utc)
|
||||
td1s = timedelta(seconds=1)
|
||||
|
||||
|
||||
def test_create() -> None:
|
||||
Event(timestamp=now, duration=timedelta(hours=13, minutes=37), data={"key": "val"})
|
||||
Event(
|
||||
timestamp=valid_timestamp,
|
||||
duration=timedelta(hours=13, minutes=37),
|
||||
data={"key": "val"},
|
||||
)
|
||||
|
||||
|
||||
def test_json_serialization() -> None:
|
||||
e = Event(
|
||||
timestamp=now, duration=timedelta(hours=13, minutes=37), data={"key": "val"}
|
||||
)
|
||||
assert e == Event(**json.loads(e.to_json_str()))
|
||||
|
||||
|
||||
def test_set_invalid_duration() -> None:
|
||||
e = Event()
|
||||
with pytest.raises(TypeError):
|
||||
e.duration = "12" # type: ignore
|
||||
|
||||
|
||||
def test_sort() -> None:
|
||||
e1 = Event(timestamp=now)
|
||||
e2 = Event(timestamp=now + td1s)
|
||||
e_sorted = sorted([e2, e1])
|
||||
assert e_sorted[0] == e1
|
||||
assert e_sorted[1] == e2
|
||||
Reference in New Issue
Block a user