64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from src.youtube_config_paths import resolve_youtube_style_config_paths
|
|
|
|
|
|
class YoutubeConfigPathTests(unittest.TestCase):
|
|
def test_non_youtube_process_uses_legacy_paths(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
cfg = root / "config"
|
|
cfg.mkdir(parents=True, exist_ok=True)
|
|
yt, url = resolve_youtube_style_config_paths(root, "tiktok")
|
|
self.assertEqual(yt, str(cfg / "youtube.ini"))
|
|
self.assertEqual(url, str(cfg / "URL_config.ini"))
|
|
|
|
def test_youtube_process_uses_legacy_pair_when_only_legacy_exists(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
cfg = root / "config"
|
|
cfg.mkdir(parents=True, exist_ok=True)
|
|
(cfg / "youtube.ini").write_text("[youtube]\nkey = legacy\n", encoding="utf-8")
|
|
(cfg / "URL_config.ini").write_text("https://live.douyin.com/1\n", encoding="utf-8")
|
|
|
|
yt, url = resolve_youtube_style_config_paths(root, "youtube")
|
|
|
|
self.assertEqual(yt, str(cfg / "youtube.ini"))
|
|
self.assertEqual(url, str(cfg / "URL_config.ini"))
|
|
|
|
def test_youtube_process_falls_back_per_file_when_only_managed_url_exists(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
cfg = root / "config"
|
|
cfg.mkdir(parents=True, exist_ok=True)
|
|
(cfg / "youtube.ini").write_text("[youtube]\nkey = legacy\n", encoding="utf-8")
|
|
managed_url = cfg / "URL_config.youtube.ini"
|
|
managed_url.write_text("https://live.douyin.com/2\n", encoding="utf-8")
|
|
|
|
yt, url = resolve_youtube_style_config_paths(root, "youtube")
|
|
|
|
self.assertEqual(yt, str(cfg / "youtube.ini"))
|
|
self.assertEqual(url, str(managed_url))
|
|
|
|
def test_youtube_process_falls_back_per_file_when_only_managed_youtube_ini_exists(self) -> None:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root = Path(tmp)
|
|
cfg = root / "config"
|
|
cfg.mkdir(parents=True, exist_ok=True)
|
|
managed_yt = cfg / "youtube.youtube.ini"
|
|
managed_yt.write_text("[youtube]\nkey = managed\n", encoding="utf-8")
|
|
(cfg / "URL_config.ini").write_text("https://live.douyin.com/3\n", encoding="utf-8")
|
|
|
|
yt, url = resolve_youtube_style_config_paths(root, "youtube")
|
|
|
|
self.assertEqual(yt, str(managed_yt))
|
|
self.assertEqual(url, str(cfg / "URL_config.ini"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|