File size: 1,812 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
# 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 argparse

import pytest

from speech_text_data_aligners.cli import annotate as annotate_cli
from speech_text_data_aligners.cli import main as main_cli
from speech_text_data_aligners.core.errors import ConfigurationError


def test_build_parser_exposes_both_thin_commands() -> None:
    parser = main_cli.build_parser()
    annotate = parser.parse_args(
        ["annotate", "in.csv", "wavs", "out.csv", "--backend", "fake"]
    )
    benchmark = parser.parse_args(
        ["benchmark", "in.csv", "gold.csv", "wavs", "--backend", "fake"]
    )
    assert annotate.command == "annotate"
    assert benchmark.command == "benchmark"


def test_main_delegates_to_registered_handler(monkeypatch: pytest.MonkeyPatch) -> None:
    calls: list[argparse.Namespace] = []
    monkeypatch.setattr(annotate_cli, "run", lambda args: (calls.append(args), 0)[1])
    assert (
        main_cli.main(["annotate", "in.csv", "wavs", "out.csv", "--backend", "fake"])
        == 0
    )
    assert calls[0].metadata_csv.name == "in.csv"


def test_main_translates_typed_error_to_status_and_stderr(
    monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
    def fail(args: argparse.Namespace) -> int:
        raise ConfigurationError("safe failure")

    monkeypatch.setattr(annotate_cli, "run", fail)
    status = main_cli.main(
        ["annotate", "in.csv", "wavs", "out.csv", "--backend", "fake"]
    )
    assert status == 2
    assert capsys.readouterr().err == "error: safe failure\n"