106 lines
3.0 KiB
Python
106 lines
3.0 KiB
Python
"""Tests for CLI parser and translation config wiring."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from src.audio_separation import DEFAULT_MIX_MODE
|
|
|
|
from main import _build_translation_config, _validate_source_args, build_parser
|
|
|
|
|
|
def test_parser_accepts_lmstudio_flags():
|
|
parser = build_parser()
|
|
|
|
args = parser.parse_args(
|
|
[
|
|
"https://youtube.com/watch?v=demo",
|
|
"--translation-backend",
|
|
"lmstudio",
|
|
"--lmstudio-base-url",
|
|
"http://localhost:1234/v1",
|
|
"--lmstudio-model",
|
|
"gemma-custom",
|
|
]
|
|
)
|
|
|
|
assert args.translation_backend == "lmstudio"
|
|
assert args.lmstudio_base_url == "http://localhost:1234/v1"
|
|
assert args.lmstudio_model == "gemma-custom"
|
|
|
|
|
|
def test_translation_config_prefers_cli_over_env(monkeypatch):
|
|
monkeypatch.setenv("LM_STUDIO_BASE_URL", "http://env-host:1234/v1")
|
|
monkeypatch.setenv("LM_STUDIO_MODEL", "env-model")
|
|
|
|
parser = build_parser()
|
|
args = parser.parse_args(
|
|
[
|
|
"https://youtube.com/watch?v=demo",
|
|
"--lmstudio-base-url",
|
|
"http://cli-host:1234/v1",
|
|
"--lmstudio-model",
|
|
"cli-model",
|
|
]
|
|
)
|
|
|
|
config = _build_translation_config(args)
|
|
|
|
assert config.base_url == "http://cli-host:1234/v1"
|
|
assert config.model == "cli-model"
|
|
|
|
|
|
def test_translation_config_uses_env_defaults(monkeypatch):
|
|
monkeypatch.setenv("LM_STUDIO_BASE_URL", "http://env-host:1234/v1")
|
|
monkeypatch.setenv("LM_STUDIO_MODEL", "env-model")
|
|
monkeypatch.setenv("LM_STUDIO_API_KEY", "env-key")
|
|
|
|
parser = build_parser()
|
|
args = parser.parse_args(["https://youtube.com/watch?v=demo"])
|
|
|
|
config = _build_translation_config(args)
|
|
|
|
assert config.base_url == "http://env-host:1234/v1"
|
|
assert config.model == "env-model"
|
|
assert config.api_key == "env-key"
|
|
|
|
|
|
def test_parser_defaults_to_instrumental_only_mix_mode():
|
|
parser = build_parser()
|
|
|
|
args = parser.parse_args(["https://youtube.com/watch?v=demo"])
|
|
|
|
assert args.mix_mode == DEFAULT_MIX_MODE
|
|
|
|
|
|
def test_parser_accepts_local_input_file_without_url():
|
|
parser = build_parser()
|
|
|
|
args = parser.parse_args(["--input-file", "demo.mp4", "--lang", "fr"])
|
|
|
|
assert args.url is None
|
|
assert args.input_file == "demo.mp4"
|
|
assert args.lang == "fr"
|
|
|
|
|
|
def test_validate_source_args_rejects_missing_source():
|
|
parser = build_parser()
|
|
args = parser.parse_args([])
|
|
|
|
try:
|
|
_validate_source_args(args)
|
|
except SystemExit as exc:
|
|
assert "Provide either" in str(exc)
|
|
else:
|
|
raise AssertionError("Expected SystemExit for missing source")
|
|
|
|
|
|
def test_validate_source_args_rejects_two_sources():
|
|
parser = build_parser()
|
|
args = parser.parse_args(["https://youtube.com/watch?v=demo", "--input-file", "demo.mp4"])
|
|
|
|
try:
|
|
_validate_source_args(args)
|
|
except SystemExit as exc:
|
|
assert "not both" in str(exc)
|
|
else:
|
|
raise AssertionError("Expected SystemExit for two sources")
|