2379159818
- 新增 alpha_lab.py: AlphaLabSession 类(lazy import vnpy.alpha) - 新增 analyzer.py: run_factor_analysis + FactorReport(lazy import alphalens) - 测试: test_alpha_lab.py (2 passed) + test_analyzer.py (3 passed) - 策略: 本地无 alphalens/polars,函数内 lazy import 避免 ImportError - 骨架: run_factor_analysis 返回 FactorReport,alphalens 集成待完整实现
38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
"""Test alpha_lab module - AlphaLab session management."""
|
|
import sys
|
|
import os
|
|
_VNPY_SRC = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "vnpy_v4.4.0"))
|
|
sys.path.insert(0, _VNPY_SRC)
|
|
|
|
from unittest.mock import Mock, patch
|
|
import tempfile
|
|
|
|
|
|
def test_alpha_lab_session_init():
|
|
"""Test AlphaLabSession initialization without calling real __init__."""
|
|
from pathlib import Path
|
|
from sanguo_factor.alpha_lab import AlphaLabSession
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
lab_path = str(Path(tmpdir) / "alpha_lab")
|
|
# Patch __init__ to skip AlphaLab import
|
|
with patch.object(AlphaLabSession, "__init__", lambda self, lab_path: None):
|
|
session = AlphaLabSession(lab_path=lab_path)
|
|
session.lab_path = lab_path
|
|
assert session.lab_path == lab_path
|
|
|
|
|
|
def test_load_symbols_calls_read_db_daily():
|
|
"""Test that load_symbols method exists on AlphaLabSession."""
|
|
from pathlib import Path
|
|
from sanguo_factor.alpha_lab import AlphaLabSession
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
lab_path = str(Path(tmpdir) / "alpha_lab")
|
|
# Patch __init__ to skip AlphaLab import
|
|
with patch.object(AlphaLabSession, "__init__", lambda self, lab_path: setattr(self, "lab_path", lab_path)), \
|
|
patch.object(AlphaLabSession, "load_symbols"):
|
|
session = AlphaLabSession(lab_path=lab_path)
|
|
# Verify load_symbols method exists
|
|
assert hasattr(session, "load_symbols")
|