Add TOML configuration file support with: - ConfigError exception class for config-related errors - load_config() function to parse TOML files with proper error handling - Tests for missing file and invalid TOML syntax scenarios Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
30 lines
879 B
Python
30 lines
879 B
Python
"""Tests for config module."""
|
|
|
|
import tempfile
|
|
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
from zzpyjenkins.config import load_config, ConfigError
|
|
|
|
|
|
def test_load_config_file_not_found():
|
|
"""Test load_config raises error when config file doesn't exist."""
|
|
with pytest.raises(ConfigError) as exc_info:
|
|
load_config(Path("/nonexistent/path/config.toml"))
|
|
assert "Config file not found" in str(exc_info.value)
|
|
|
|
|
|
def test_load_config_invalid_toml():
|
|
"""Test load_config raises error for invalid TOML syntax."""
|
|
with tempfile.NamedTemporaryFile(mode="w", suffix=".toml", delete=False) as f:
|
|
f.write("invalid toml [[[[")
|
|
temp_path = Path(f.name)
|
|
|
|
try:
|
|
with pytest.raises(ConfigError) as exc_info:
|
|
load_config(temp_path)
|
|
assert "Invalid TOML syntax" in str(exc_info.value)
|
|
finally:
|
|
temp_path.unlink()
|