pltobing's picture
chore(repo): finalize licensing and documentation
51e84d2
Raw History Blame Contribute Delete
1.95 kB
# License: Apache-2.0 License
# Created by: Patrick Lumbantobing, VertoX-AI
# Copyright (c) 2026 VertoX-AI. All rights reserved.
#
# This work is licensed under the Apache-2.0 License.
# To view a copy of this license, visit
# https://www.apache.org/licenses/LICENSE-2.0
from __future__ import annotations
from dataclasses import FrozenInstanceError
from pathlib import Path
import pytest
from speech_text_data_aligners.core.models import (
AlignmentFailure,
AlignmentOutcome,
AlignmentProvenance,
AlignmentRequest,
AlignmentResult,
Diagnostic,
DiagnosticSeverity,
LexicalWord,
WordAlignment,
)
def test_neutral_records_are_typed_and_immutable() -> None:
diagnostic = Diagnostic("note", DiagnosticSeverity.INFO, "safe", "parse")
request = AlignmentRequest("r", Path("a.wav"), "Hello", 1.0)
word = LexicalWord(0, "Hello", 0, 5)
alignment = WordAlignment(word, 0.1, 0.5, 0.9)
provenance = AlignmentProvenance(
backend_name="fake", artifacts=("ctm",), attributes=(("batch", 1),)
)
result = AlignmentResult("r", (alignment,), provenance, (diagnostic,), 0.2)
outcome = AlignmentOutcome(result=result)
assert request.transcript == "Hello"
assert outcome.succeeded
assert outcome.request_id == "r"
assert provenance.attributes == (("batch", 1),)
with pytest.raises(FrozenInstanceError):
word.text = "changed" # type: ignore[misc]
def test_outcome_enforces_exactly_one_variant() -> None:
failure = AlignmentFailure("r", "bad", "test", "no")
outcome = AlignmentOutcome(failure=failure)
assert not outcome.succeeded
assert outcome.request_id == "r"
with pytest.raises(ValueError, match="exactly one"):
AlignmentOutcome()
with pytest.raises(ValueError, match="exactly one"):
AlignmentOutcome(
result=AlignmentResult("r", (), AlignmentProvenance("fake")),
failure=failure,
)