Initial version of application
This commit is contained in:
88
tests/test_corrections.py
Normal file
88
tests/test_corrections.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import pytest
|
||||
|
||||
from audita.corrections import apply_corrections
|
||||
from audita.errors import AuditaValidationError
|
||||
from audita.schemas import CorrectionCandidate, parse_transcript_json
|
||||
|
||||
|
||||
def _transcript():
|
||||
return parse_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"speaker": "Eric", "start": 10.0, "end": 11.0, "text": "I ask Chontia."},
|
||||
{"speaker": "Mike", "start": 0.0, "end": 1.0, "text": "Then Lyra."}
|
||||
]
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_apply_corrections_uses_threshold_and_sorts_chronologically():
|
||||
transcript = _transcript()
|
||||
corrections = [
|
||||
CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
]
|
||||
|
||||
revised = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
|
||||
assert [segment.speaker for segment in revised] == ["Mike", "Eric"]
|
||||
assert revised[1].text == "I ask Chauntea."
|
||||
|
||||
|
||||
def test_apply_corrections_ignores_below_threshold():
|
||||
transcript = _transcript()
|
||||
corrections = [
|
||||
CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.79,
|
||||
)
|
||||
]
|
||||
|
||||
revised = apply_corrections(transcript, corrections, confidence_threshold=0.8)
|
||||
|
||||
assert revised[1].text == "I ask Chontia."
|
||||
|
||||
|
||||
def test_apply_corrections_rejects_duplicate_targets():
|
||||
transcript = _transcript()
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
original_text="I ask Chontia.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
|
||||
with pytest.raises(AuditaValidationError):
|
||||
apply_corrections(transcript, [correction, correction], confidence_threshold=0.8)
|
||||
|
||||
|
||||
def test_apply_corrections_rejects_mismatched_original_text():
|
||||
transcript = _transcript()
|
||||
correction = CorrectionCandidate(
|
||||
segment_index=0,
|
||||
speaker="Eric",
|
||||
start=10.0,
|
||||
end=11.0,
|
||||
original_text="Different text.",
|
||||
corrected_text="I ask Chauntea.",
|
||||
confidence=0.8,
|
||||
)
|
||||
|
||||
with pytest.raises(AuditaValidationError):
|
||||
apply_corrections(transcript, [correction], confidence_threshold=0.8)
|
||||
|
||||
Reference in New Issue
Block a user