3422372948
- Fix 1: 移除误 commit 的 __pycache__ 文件 - Fix 2: 创建 pytest.ini 解决 PYTHONPATH 问题 - Fix 3: load_config 添加错误处理(FileNotFoundError + ValueError) Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
917 B
Python
33 lines
917 B
Python
# tests/data/test_config.py
|
|
import pytest
|
|
from sanguo_data.config import load_config, DataConfig
|
|
|
|
def test_load_config_returns_dataconfig(tmp_path):
|
|
yaml_content = """
|
|
data_paths:
|
|
daily_dir: /tmp/daily
|
|
minute_15_dir: /tmp/15min
|
|
vnpy_db: /tmp/quant.db
|
|
stock_list: /tmp/stock.csv
|
|
data_sources:
|
|
daily:
|
|
- name: eastmoney
|
|
enabled: true
|
|
interval: 4.0
|
|
validation:
|
|
price_positive: true
|
|
performance:
|
|
max_retries: 3
|
|
"""
|
|
p = tmp_path / "config.yaml"
|
|
p.write_text(yaml_content)
|
|
cfg = load_config(str(p))
|
|
assert isinstance(cfg, DataConfig)
|
|
assert cfg.data_paths["daily_dir"] == "/tmp/daily"
|
|
assert cfg.data_sources["daily"][0]["name"] == "eastmoney"
|
|
assert cfg.performance["max_retries"] == 3
|
|
|
|
def test_load_config_raises_on_missing_file():
|
|
with pytest.raises(FileNotFoundError, match="配置文件不存在"):
|
|
load_config("/nonexistent/path/config.yaml")
|