from pathlib import Path import pytest from restreamer.config import load_channels def test_load_channels_parses_valid_file(tmp_path: Path) -> None: channels_file = tmp_path / "channels.yaml" channels_file.write_text( """ channels: - id: news name: "News Live" url: "https://www.youtube.com/watch?v=abc123" - id: music name: "Music Live" url: "https://www.youtube.com/watch?v=def456" refresh_interval_seconds: 3600 """, encoding="utf-8", ) channels = load_channels(channels_file) assert [c.id for c in channels] == ["news", "music"] assert channels[1].refresh_interval_seconds == 3600 def test_load_channels_missing_file_raises(tmp_path: Path) -> None: with pytest.raises(FileNotFoundError): load_channels(tmp_path / "does_not_exist.yaml") def test_load_channels_rejects_duplicate_ids(tmp_path: Path) -> None: channels_file = tmp_path / "channels.yaml" channels_file.write_text( """ channels: - id: news name: "News Live" url: "https://www.youtube.com/watch?v=abc123" - id: news name: "News Live Again" url: "https://www.youtube.com/watch?v=def456" """, encoding="utf-8", ) with pytest.raises(ValueError, match="Duplicate channel id"): load_channels(channels_file)