41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import pytest
|
|
|
|
from audita.chunking import chunk_transcript
|
|
from audita.errors import AuditaValidationError
|
|
from audita.schemas import parse_transcript_json
|
|
|
|
|
|
class CountEstimator:
|
|
def estimate_json(self, value):
|
|
return len(value) * 10
|
|
|
|
|
|
def _segments(count):
|
|
payload = [
|
|
{"speaker": "Eric", "start": float(i), "end": float(i + 1), "text": f"Segment {i}"}
|
|
for i in range(count)
|
|
]
|
|
import json
|
|
|
|
return parse_transcript_json(json.dumps(payload))
|
|
|
|
|
|
def test_chunk_transcript_splits_on_segment_boundaries():
|
|
sections = chunk_transcript(_segments(5), max_section_tokens=20, estimator=CountEstimator())
|
|
|
|
assert [len(section.segments) for section in sections] == [2, 2, 1]
|
|
assert [section.start_index for section in sections] == [0, 2, 4]
|
|
|
|
|
|
def test_chunk_transcript_allows_exact_limit():
|
|
sections = chunk_transcript(_segments(2), max_section_tokens=20, estimator=CountEstimator())
|
|
|
|
assert len(sections) == 1
|
|
assert len(sections[0].segments) == 2
|
|
|
|
|
|
def test_chunk_transcript_rejects_oversized_single_segment():
|
|
with pytest.raises(AuditaValidationError):
|
|
chunk_transcript(_segments(1), max_section_tokens=9, estimator=CountEstimator())
|
|
|