feat: add get_default_config_path function
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Configuration file handling."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tomllib
|
||||
|
||||
@@ -10,6 +11,21 @@ class ConfigError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def get_default_config_path() -> Path:
|
||||
"""Get the default config file path.
|
||||
|
||||
Returns:
|
||||
Path to ~/.config/zzpyjenkins/config.toml
|
||||
"""
|
||||
xdg_config = os.environ.get("XDG_CONFIG_HOME")
|
||||
if xdg_config:
|
||||
config_dir = Path(xdg_config)
|
||||
else:
|
||||
config_dir = Path.home() / ".config"
|
||||
|
||||
return config_dir / "zzpyjenkins" / "config.toml"
|
||||
|
||||
|
||||
def load_config(config_path: Path) -> dict:
|
||||
"""Load and parse TOML config file."""
|
||||
if not config_path.exists():
|
||||
|
||||
@@ -5,7 +5,12 @@ import tempfile
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
|
||||
from zzpyjenkins.config import load_config, ConfigError, get_server_config
|
||||
from zzpyjenkins.config import (
|
||||
load_config,
|
||||
ConfigError,
|
||||
get_server_config,
|
||||
get_default_config_path,
|
||||
)
|
||||
|
||||
|
||||
def test_load_config_file_not_found():
|
||||
@@ -68,3 +73,11 @@ def test_get_server_config_missing_field():
|
||||
with pytest.raises(ConfigError) as exc_info:
|
||||
get_server_config(config, "incomplete")
|
||||
assert "password" in str(exc_info.value)
|
||||
|
||||
|
||||
def test_get_default_config_path():
|
||||
"""Test default config path is correct."""
|
||||
path = get_default_config_path()
|
||||
assert path.name == "config.toml"
|
||||
assert ".config" in str(path)
|
||||
assert "zzpyjenkins" in str(path)
|
||||
|
||||
Reference in New Issue
Block a user