39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
os.environ["SOMAFM_IMAGES"] = "0"
|
|
|
|
import pytest
|
|
|
|
from somafm_tui import api, config
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def isolated_state(tmp_path, monkeypatch):
|
|
"""Keep tests out of the real ~/.config and ~/.cache."""
|
|
config_dir = tmp_path / "config"
|
|
cache_dir = tmp_path / "cache"
|
|
songs_dir = cache_dir / "songs"
|
|
runtime_dir = tmp_path / "run"
|
|
|
|
for attr, value in (
|
|
("CONFIG_DIR", config_dir),
|
|
("CACHE_DIR", cache_dir),
|
|
("SONGS_CACHE_DIR", songs_dir),
|
|
("RUNTIME_DIR", runtime_dir),
|
|
("CONFIG_PATH", config_dir / "config.json"),
|
|
("CHANNELS_CACHE", cache_dir / "channels.json"),
|
|
("PLAYLIST_CACHE", cache_dir / "playlists.json"),
|
|
):
|
|
monkeypatch.setattr(config, attr, value)
|
|
|
|
def ensure_dirs() -> None:
|
|
for path in (config_dir, cache_dir, songs_dir, runtime_dir):
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
|
|
monkeypatch.setattr(config, "ensure_dirs", ensure_dirs)
|
|
monkeypatch.setattr(api, "_PLAYLIST_CACHE", None)
|
|
ensure_dirs()
|
|
yield
|