68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
import os
|
|
import pytest
|
|
from pathlib import Path
|
|
from src import paths
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def reset_paths():
|
|
paths.reset_resolved()
|
|
yield
|
|
paths.reset_resolved()
|
|
|
|
def test_default_paths():
|
|
assert paths.get_conductor_dir() == Path("conductor")
|
|
assert paths.get_logs_dir() == Path("logs/sessions")
|
|
assert paths.get_scripts_dir() == Path("scripts/generated")
|
|
assert paths.get_config_path() == Path("config.toml")
|
|
assert paths.get_tracks_dir() == Path("conductor/tracks")
|
|
assert paths.get_archive_dir() == Path("conductor/archive")
|
|
|
|
def test_env_var_overrides(monkeypatch):
|
|
monkeypatch.setenv("SLOP_CONDUCTOR_DIR", "custom_conductor")
|
|
monkeypatch.setenv("SLOP_LOGS_DIR", "custom_logs")
|
|
monkeypatch.setenv("SLOP_SCRIPTS_DIR", "custom_scripts")
|
|
|
|
assert paths.get_conductor_dir() == Path("custom_conductor")
|
|
assert paths.get_logs_dir() == Path("custom_logs")
|
|
assert paths.get_scripts_dir() == Path("custom_scripts")
|
|
assert paths.get_tracks_dir() == Path("custom_conductor/tracks")
|
|
|
|
def test_config_overrides(tmp_path, monkeypatch):
|
|
config_file = tmp_path / "custom_config.toml"
|
|
content = """
|
|
[paths]
|
|
conductor_dir = "cfg_conductor"
|
|
logs_dir = "cfg_logs"
|
|
scripts_dir = "cfg_scripts"
|
|
"""
|
|
config_file.write_text(content)
|
|
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
|
|
|
# Need to update the _CONFIG_PATH in paths.py since it's set at import
|
|
# Actually, the get_config_path() uses _CONFIG_PATH which is Path(os.environ.get("SLOP_CONFIG", "config.toml"))
|
|
# But it's defined at module level. Let's see if we can reload it or if monkeypatching early enough works.
|
|
# In src/paths.py: _CONFIG_PATH: Path = Path(os.environ.get("SLOP_CONFIG", "config.toml"))
|
|
# This is set when src.paths is first imported.
|
|
|
|
# For the test to work, we might need to manually set paths._CONFIG_PATH or reload the module.
|
|
# paths._CONFIG_PATH = config_file # No longer needed
|
|
|
|
assert paths.get_conductor_dir() == Path("cfg_conductor")
|
|
assert paths.get_logs_dir() == Path("cfg_logs")
|
|
assert paths.get_scripts_dir() == Path("cfg_scripts")
|
|
|
|
def test_precedence(tmp_path, monkeypatch):
|
|
config_file = tmp_path / "custom_config.toml"
|
|
content = """
|
|
[paths]
|
|
conductor_dir = "cfg_conductor"
|
|
"""
|
|
config_file.write_text(content)
|
|
monkeypatch.setenv("SLOP_CONFIG", str(config_file))
|
|
monkeypatch.setenv("SLOP_CONDUCTOR_DIR", "env_conductor")
|
|
|
|
# paths._CONFIG_PATH = config_file # No longer needed
|
|
|
|
# Env var should take precedence over config
|
|
assert paths.get_conductor_dir() == Path("env_conductor")
|