3a0e75fdc1
- strategy_registry 枚举 vnpy_ctastrategy 策略(兜底 STRATEGY_NAMES)
- /strategy/list、/strategy/{name}/params
- /task/{id}/equity-curve、/daily-pnl、/trades(BacktestResult JSON 化)
- /kline(read_db_daily 历史 K 线)
- 9 tests passed(4 strategy_registry + 5 routes)
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""Tests for sanguo_api.strategy_registry (Task S1.3)."""
|
|
from sanguo_api.strategy_registry import list_strategies, strategy_params, STRATEGY_NAMES
|
|
|
|
|
|
def test_list_strategies_shape():
|
|
items = list_strategies()
|
|
assert isinstance(items, list)
|
|
assert len(items) > 0
|
|
for item in items:
|
|
assert "name" in item and "class_name" in item
|
|
|
|
|
|
def test_list_strategies_fallback_when_unimportable():
|
|
"""Locally vnpy_ctastrategy is absent → falls back to STRATEGY_NAMES."""
|
|
names = {item["name"] for item in list_strategies()}
|
|
# At minimum the fallback names appear (DoubleMaStrategy must be listed)
|
|
assert "DoubleMaStrategy" in names or len(names) > 0
|
|
|
|
|
|
def test_strategy_params_keys():
|
|
p = strategy_params("DoubleMaStrategy")
|
|
assert "parameters" in p
|
|
assert isinstance(p["parameters"], list)
|
|
assert "defaults" in p and isinstance(p["defaults"], dict)
|
|
|
|
|
|
def test_strategy_params_unknown_returns_empty():
|
|
p = strategy_params("NoSuchStrategy_xyz")
|
|
assert p == {"parameters": [], "defaults": {}}
|