import pytest from locutus import LocutusConfig def make_toml(path: str, text: str) -> None: with open(path, 'wb') as f: f.write(text.encode()) def make_rc(path: str, text: str) -> None: with open(path, 'w') as f: f.write(text) @pytest.fixture def temp_config_files(tmp_path): # Make temp locutus.toml toml_content = """ [includes] paths = ["/test/inc1", "/test/inc2"] [excludes] paths = ["*.cache"] [prune] keep_last = 2 keep_daily = 3 [compact] enabled = true """ toml_path = tmp_path / 'locutus.toml' make_toml(str(toml_path), toml_content) # Make temp locutus.rc rc_content = ( 'export BORG_REPO="/tmp/repo"\nexport BORG_PASSPHRASE="hunter2"\n' ) rc_path = tmp_path / 'locutus.rc' make_rc(str(rc_path), rc_content) return str(toml_path), str(rc_path) def test_config_loads_correctly(temp_config_files): toml_path, rc_path = temp_config_files cfg = LocutusConfig(toml_path, rc_path) assert cfg.toml_path == toml_path assert cfg.rc_path == rc_path assert cfg.includes == ['/test/inc1', '/test/inc2'] assert cfg.excludes == ['*.cache'] assert cfg.prune['keep_last'] == 2 assert cfg.prune['keep_daily'] == 3 assert cfg.compact is True assert cfg.get_repo() == '/tmp/repo' assert cfg.get_passphrase() == 'hunter2' def test_missing_rc(tmp_path): # Valid toml, missing rc toml_content = """ [includes] paths = ["/test/inc1"] """ toml_path = tmp_path / 'locutus.toml' make_toml(str(toml_path), toml_content) rc_path = tmp_path / 'missing.rc' cfg = LocutusConfig(str(toml_path), str(rc_path)) assert cfg.includes == ['/test/inc1'] assert cfg.get_repo() is None assert cfg.get_passphrase() is None def test_missing_toml(tmp_path): # Missing toml toml_path = tmp_path / 'missing.toml' rc_path = tmp_path / 'locutus.rc' make_rc(str(rc_path), 'export BORG_REPO="/tmp/repo"\n') with pytest.raises(FileNotFoundError): LocutusConfig(str(toml_path), str(rc_path)) def test_partial_rc(tmp_path): # Valid toml, partial rc (no passphrase) toml_content = """ [includes] paths = ["/home/test"] """ toml_path = tmp_path / 'locutus.toml' make_toml(str(toml_path), toml_content) rc_path = tmp_path / 'locutus.rc' make_rc(str(rc_path), 'export BORG_REPO="/somewhere/repo"\n') cfg = LocutusConfig(str(toml_path), str(rc_path)) assert cfg.get_repo() == '/somewhere/repo' assert cfg.get_passphrase() is None