File size: 1,998 Bytes
51e84d2
 
 
 
 
 
 
 
fc1dcbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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

import pytest

from speech_text_data_aligners.core.errors import (
    AlignmentValidationError,
    AudioError,
    BackendExecutionError,
    BackendOutputError,
    BackendUnavailableError,
    BenchmarkError,
    ConfigurationError,
    MetadataError,
    SpeechTextAlignerError,
    TranscriptError,
    TranscriptMappingError,
    failure_from_error,
)


@pytest.mark.parametrize(
    ("error_type", "code", "category"),
    [
        (ConfigurationError, "configuration_error", "configuration"),
        (MetadataError, "metadata_error", "metadata"),
        (AudioError, "audio_error", "audio"),
        (TranscriptError, "transcript_error", "transcript"),
        (BackendUnavailableError, "backend_unavailable", "backend"),
        (BackendExecutionError, "backend_execution_error", "backend"),
        (BackendOutputError, "backend_output_error", "backend"),
        (TranscriptMappingError, "transcript_mapping_error", "mapping"),
        (AlignmentValidationError, "alignment_validation_error", "validation"),
        (BenchmarkError, "benchmark_error", "benchmark"),
    ],
)
def test_error_taxonomy_has_stable_codes(
    error_type: type[SpeechTextAlignerError], code: str, category: str
) -> None:
    error = error_type("safe", context=(("row", 1),), retryable=True)
    failure = failure_from_error(error, request_id="000001")
    assert (failure.code, failure.category, failure.message, failure.retryable) == (
        code,
        category,
        "safe",
        True,
    )


def test_base_error_is_an_exception() -> None:
    error = SpeechTextAlignerError("message")
    assert str(error) == "message"
    assert error.context == ()
    assert not error.retryable