feat(factor): 挂载 vnpy Alpha101(82)+Alpha158(158) 全量表达式进注册表——空df实例化零成本提取,导入即注册,幂等 [vps]
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# tests/factor/test_alpha_datasets.py
|
||||
"""Alpha101/158 全量挂载:数量/幂等/类别/表达式可用性."""
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "vnpy_v4.4.0")))
|
||||
|
||||
from sanguo_factor.alpha_datasets import mount_all
|
||||
from sanguo_factor.registry import list_factors, get_factor, _REGISTRY
|
||||
|
||||
|
||||
def test_mount_all_counts():
|
||||
# Clear registry first (factors already registered at module import time)
|
||||
_REGISTRY.clear()
|
||||
counts = mount_all()
|
||||
assert counts == {"alpha101": 82, "alpha158": 158}
|
||||
|
||||
|
||||
def test_categories_and_expression():
|
||||
mount_all()
|
||||
a101 = list_factors("alpha101")
|
||||
assert {f["name"] for f in a101} >= {"alpha1", "alpha2", "alpha5"}
|
||||
assert get_factor("alpha5")["expression"].count("vwap") >= 1 # alpha5 显式用 vwap
|
||||
a158 = list_factors("alpha158")
|
||||
names = {f["name"] for f in a158}
|
||||
assert {"kmid", "klen", "roc_5", "ma_20", "std_20", "wvma_20", "vwap_0"} <= names
|
||||
|
||||
|
||||
def test_mount_idempotent():
|
||||
# Clear registry and mount fresh
|
||||
_REGISTRY.clear()
|
||||
mount_all()
|
||||
n_before = len(_REGISTRY)
|
||||
mount_all()
|
||||
assert len(_REGISTRY) == n_before
|
||||
|
||||
|
||||
def test_import_side_effect_registers():
|
||||
# sanguo_factor 包导入即挂载(下游 /factor/list 依赖)
|
||||
import sanguo_factor
|
||||
assert len(list_factors("alpha101")) == 82
|
||||
Reference in New Issue
Block a user