# 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"