"""Tests for configuration loading and validation.""" from __future__ import annotations from pathlib import Path import pytest from video_vec2wav2_tokenizer.utils.config import Config, load_config def test_defaults_load() -> None: cfg = load_config() assert cfg.sample_rate == 16000 assert cfg.channels == 1 assert cfg.audio_dir == Path(cfg.output_dir) / "audio" def test_overrides_take_priority() -> None: cfg = load_config(overrides={"sample_rate": 8000, "device": "cpu"}) assert cfg.sample_rate == 8000 assert cfg.device == "cpu" def test_none_overrides_are_ignored() -> None: cfg = load_config(overrides={"device": None}) assert cfg.device == "auto" # default preserved def test_user_file_overrides_default(tmp_path: Path) -> None: p = tmp_path / "c.yaml" p.write_text("whisper_model: tiny\nsample_rate: 22050\n", encoding="utf-8") cfg = load_config(p) assert cfg.whisper_model == "tiny" assert cfg.sample_rate == 22050 def test_validate_rejects_bad_values() -> None: with pytest.raises(ValueError): Config(channels=3).validate() with pytest.raises(ValueError): Config(max_segment_length=0.5, min_segment_length=1.0).validate() def test_missing_file_raises() -> None: with pytest.raises(FileNotFoundError): load_config("does-not-exist.yaml") def test_derived_paths() -> None: cfg = Config(output_dir="out") assert cfg.metadata_csv == Path("out/metadata.csv") assert cfg.dataset_jsonl == Path("out/dataset.jsonl") assert cfg.tts_metadata_csv == Path("out/tts_metadata.csv") assert cfg.report_json == Path("out/report.json")