69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from mka.application.config import AppSettings, ConfigurationError
|
|
|
|
|
|
def test_settings_require_whisper_model() -> None:
|
|
settings = AppSettings(data_root=Path("runs"), whisper_model=None)
|
|
|
|
with pytest.raises(ConfigurationError, match="MKA_WHISPER_MODEL"):
|
|
settings.validate_for_processing()
|
|
|
|
|
|
def test_settings_reject_missing_whisper_model(tmp_path: Path) -> None:
|
|
settings = AppSettings(
|
|
data_root=tmp_path / "runs",
|
|
whisper_model=tmp_path / "missing.bin",
|
|
)
|
|
|
|
with pytest.raises(ConfigurationError, match="does not exist"):
|
|
settings.validate_for_processing()
|
|
|
|
|
|
def test_settings_accept_valid_native_configuration(tmp_path: Path) -> None:
|
|
model = tmp_path / "model.bin"
|
|
model.write_bytes(b"model")
|
|
settings = AppSettings(data_root=tmp_path / "runs", whisper_model=model)
|
|
|
|
settings.validate_for_processing()
|
|
|
|
assert settings.diarization_runtime == "native"
|
|
assert settings.diarization_container_args == ()
|
|
|
|
|
|
def test_environment_defaults_to_no_diarization_container_args(monkeypatch) -> None:
|
|
monkeypatch.delenv("MKA_DIARIZATION_CONTAINER_ARGS", raising=False)
|
|
|
|
settings = AppSettings.from_environment()
|
|
|
|
assert settings.diarization_container_args == ()
|
|
|
|
|
|
def test_environment_parses_multiple_ordered_container_args(monkeypatch) -> None:
|
|
monkeypatch.setenv(
|
|
"MKA_DIARIZATION_CONTAINER_ARGS",
|
|
'["--device=/dev/kfd", "--device=/dev/dri", "--group-add", "video"]',
|
|
)
|
|
|
|
settings = AppSettings.from_environment()
|
|
|
|
assert settings.diarization_container_args == (
|
|
"--device=/dev/kfd",
|
|
"--device=/dev/dri",
|
|
"--group-add",
|
|
"video",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"value",
|
|
["not-json", '"--flag"', '["valid", ""]', '["valid", 1]'],
|
|
)
|
|
def test_environment_rejects_invalid_container_args(monkeypatch, value: str) -> None:
|
|
monkeypatch.setenv("MKA_DIARIZATION_CONTAINER_ARGS", value)
|
|
|
|
with pytest.raises(ConfigurationError, match="JSON array"):
|
|
AppSettings.from_environment()
|