45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
"""Tests for configuration system."""
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
import os
|
||
|
|
import tempfile
|
||
|
|
from pathlib import Path
|
||
|
|
from unittest.mock import patch
|
||
|
|
from src.core.config import Config, get_config
|
||
|
|
|
||
|
|
|
||
|
|
class TestConfig:
|
||
|
|
"""Tests for Config class."""
|
||
|
|
|
||
|
|
def test_config_initialization(self, tmp_path):
|
||
|
|
"""Test config initialization."""
|
||
|
|
config_file = tmp_path / "config.yaml"
|
||
|
|
config = Config(config_file=str(config_file))
|
||
|
|
assert config is not None
|
||
|
|
assert config.config_dir is not None
|
||
|
|
assert config.data_dir is not None
|
||
|
|
|
||
|
|
def test_config_get(self, tmp_path):
|
||
|
|
"""Test config get method."""
|
||
|
|
config_file = tmp_path / "config.yaml"
|
||
|
|
config = Config(config_file=str(config_file))
|
||
|
|
# Test nested key access
|
||
|
|
value = config.get('paper_trading.default_capital')
|
||
|
|
assert value is not None
|
||
|
|
|
||
|
|
def test_config_set(self, tmp_path):
|
||
|
|
"""Test config set method."""
|
||
|
|
config_file = tmp_path / "config.yaml"
|
||
|
|
config = Config(config_file=str(config_file))
|
||
|
|
config.set('paper_trading.default_capital', 200.0)
|
||
|
|
value = config.get('paper_trading.default_capital')
|
||
|
|
assert value == 200.0
|
||
|
|
|
||
|
|
def test_config_defaults(self, tmp_path):
|
||
|
|
"""Test default configuration values."""
|
||
|
|
config_file = tmp_path / "config.yaml"
|
||
|
|
config = Config(config_file=str(config_file))
|
||
|
|
assert config.get('paper_trading.default_capital') == 100.0
|
||
|
|
assert config.get('database.type') == 'postgresql'
|
||
|
|
|