mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-11 05:07:25 -04:00
feat: add config file loading with error handling
Implement load_config() function with comprehensive error handling - Loads and parses JSON config files - Raises ConfigValidationError for missing files - Raises ConfigValidationError for malformed JSON - Includes 3 passing tests for all error cases Test coverage: - test_load_config_valid_json: Verifies successful JSON parsing - test_load_config_file_not_found: Validates error on missing file - test_load_config_invalid_json: Validates error on malformed JSON
This commit is contained in:
37
tests/unit/test_config_merger.py
Normal file
37
tests/unit/test_config_merger.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import pytest
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from tools.config_merger import load_config, ConfigValidationError
|
||||
|
||||
|
||||
def test_load_config_valid_json():
|
||||
"""Test loading a valid JSON config file"""
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
||||
json.dump({"key": "value"}, f)
|
||||
temp_path = f.name
|
||||
|
||||
try:
|
||||
result = load_config(temp_path)
|
||||
assert result == {"key": "value"}
|
||||
finally:
|
||||
Path(temp_path).unlink()
|
||||
|
||||
|
||||
def test_load_config_file_not_found():
|
||||
"""Test loading non-existent config file"""
|
||||
with pytest.raises(ConfigValidationError, match="not found"):
|
||||
load_config("/nonexistent/path.json")
|
||||
|
||||
|
||||
def test_load_config_invalid_json():
|
||||
"""Test loading malformed JSON"""
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
||||
f.write("{invalid json")
|
||||
temp_path = f.name
|
||||
|
||||
try:
|
||||
with pytest.raises(ConfigValidationError, match="Invalid JSON"):
|
||||
load_config(temp_path)
|
||||
finally:
|
||||
Path(temp_path).unlink()
|
||||
Reference in New Issue
Block a user