124 lines
3.8 KiB
Python
124 lines
3.8 KiB
Python
from uuid import uuid4
|
|
|
|
import pytest
|
|
|
|
from noteflow.domain.ai.citations import SegmentCitation
|
|
|
|
EXPECTED_DURATION_SECONDS = 15.0
|
|
FROZEN_ASSIGNMENT_MESSAGE = "cannot assign to field"
|
|
|
|
|
|
class TestSegmentCitation:
|
|
def test_creation_with_valid_values(self) -> None:
|
|
meeting_id = uuid4()
|
|
citation = SegmentCitation(
|
|
meeting_id=meeting_id,
|
|
segment_id=1,
|
|
start_time=0.0,
|
|
end_time=5.0,
|
|
text="Test segment text",
|
|
score=0.95,
|
|
)
|
|
|
|
assert citation.meeting_id == meeting_id, "Meeting ID should be preserved"
|
|
assert citation.segment_id == 1, "Segment ID should be preserved"
|
|
assert citation.start_time == 0.0, "Start time should be preserved"
|
|
assert citation.end_time == 5.0, "End time should be preserved"
|
|
assert citation.text == "Test segment text", "Text should be preserved"
|
|
assert citation.score == 0.95, "Score should be preserved"
|
|
|
|
def test_duration_property_returns_delta(self) -> None:
|
|
citation = SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=10.0,
|
|
end_time=25.0,
|
|
text="Test",
|
|
)
|
|
|
|
assert citation.duration == EXPECTED_DURATION_SECONDS, (
|
|
"Duration should equal end_time - start_time"
|
|
)
|
|
|
|
def test_default_score_is_zero(self) -> None:
|
|
citation = SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=0.0,
|
|
end_time=1.0,
|
|
text="Test",
|
|
)
|
|
|
|
assert citation.score == 0.0, "Default score should be zero"
|
|
|
|
def test_rejects_negative_segment_id(self) -> None:
|
|
with pytest.raises(ValueError, match="segment_id must be non-negative"):
|
|
SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=-1,
|
|
start_time=0.0,
|
|
end_time=5.0,
|
|
text="Test",
|
|
)
|
|
|
|
def test_rejects_negative_start_time(self) -> None:
|
|
with pytest.raises(ValueError, match="start_time must be non-negative"):
|
|
SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=-1.0,
|
|
end_time=5.0,
|
|
text="Test",
|
|
)
|
|
|
|
def test_rejects_end_time_before_start_time(self) -> None:
|
|
with pytest.raises(ValueError, match="end_time must be >= start_time"):
|
|
SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=10.0,
|
|
end_time=5.0,
|
|
text="Test",
|
|
)
|
|
|
|
@pytest.mark.parametrize(
|
|
"invalid_score",
|
|
[
|
|
pytest.param(-0.1, id="negative"),
|
|
pytest.param(1.1, id="above_one"),
|
|
],
|
|
)
|
|
def test_rejects_invalid_score(self, invalid_score: float) -> None:
|
|
with pytest.raises(ValueError, match="score must be between 0 and 1"):
|
|
SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=0.0,
|
|
end_time=5.0,
|
|
text="Test",
|
|
score=invalid_score,
|
|
)
|
|
|
|
def test_accepts_zero_duration(self) -> None:
|
|
citation = SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=5.0,
|
|
end_time=5.0,
|
|
text="Instant moment",
|
|
)
|
|
|
|
assert citation.duration == 0.0, "Zero-length segments should have zero duration"
|
|
|
|
def test_citation_is_frozen(self) -> None:
|
|
citation = SegmentCitation(
|
|
meeting_id=uuid4(),
|
|
segment_id=1,
|
|
start_time=0.0,
|
|
end_time=5.0,
|
|
text="Test",
|
|
)
|
|
|
|
with pytest.raises(AttributeError, match=FROZEN_ASSIGNMENT_MESSAGE):
|
|
citation.text = "Modified"
|