feat(strategy): registry 扩展自研目录扫描(AST)+文件读写+py_compile; __init__ 惰性化(纯逻辑模块脱离 fastapi 可单测) [nas]
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"""Tests for sanguo_api.strategy_registry (Task S1.3)."""
|
||||
from sanguo_api.strategy_registry import list_strategies, strategy_params, STRATEGY_NAMES
|
||||
from sanguo_api.strategy_registry import (
|
||||
list_strategies, strategy_params, STRATEGY_NAMES,
|
||||
list_strategy_files, read_strategy_file,
|
||||
)
|
||||
|
||||
|
||||
def test_list_strategies_shape():
|
||||
@@ -27,3 +30,30 @@ def test_strategy_params_keys():
|
||||
def test_strategy_params_unknown_returns_empty():
|
||||
p = strategy_params("NoSuchStrategy_xyz")
|
||||
assert p == {"parameters": [], "defaults": {}}
|
||||
|
||||
|
||||
def test_list_strategy_files_returns_dirs():
|
||||
data = list_strategy_files()
|
||||
assert "files" in data and isinstance(data["files"], list)
|
||||
dirs = {f["dir"] for f in data["files"]}
|
||||
# 自研目录至少出现一个(sanguo_portfolio/strategies 有真实策略文件)
|
||||
assert any("sanguo_trader/strategy" in d or "sanguo_portfolio/strategies" in d for d in dirs)
|
||||
|
||||
|
||||
def test_list_strategy_files_item_shape():
|
||||
data = list_strategy_files()
|
||||
if not data["files"]:
|
||||
return
|
||||
f = data["files"][0]
|
||||
for k in ("name", "dir", "class_name", "type"):
|
||||
assert k in f
|
||||
|
||||
|
||||
def test_read_strategy_file_returns_code():
|
||||
data = list_strategy_files()
|
||||
if not data["files"]:
|
||||
return
|
||||
f = data["files"][0]
|
||||
content = read_strategy_file(f["name"])
|
||||
assert "code" in content and isinstance(content["code"], str)
|
||||
assert content["class_name"] == f["class_name"]
|
||||
|
||||
Reference in New Issue
Block a user