tradingSystem/scripts/run_tests.py

45 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
"""
全部单测一次跑完 (零外部依赖, 不连库)
======================================
运行: docker compose run --rm pms-web python scripts/run_tests.py
包含:
test_core_units.py 仓位规划器 / 安全垫与成本账 (14 例)
test_batch2_units.py 命令状态机 / 方案生成器 / 回放对账纯逻辑 (35 例)
test_batch3_units.py 规则闸 / 择时执行器实现B 纯逻辑 (18 例)
test_batch4_units.py 动作引擎 四类自主动作触发与数量口径 (11 例)
test_wiring.py 装配自检: 服务层→核心→落表 全链路 (内存桩) (30 例)
任一子集失败即整体失败 (退出码 1)。
"""
import os
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(HERE)
SUITES = ["test_core_units.py", "test_batch2_units.py", "test_batch3_units.py",
"test_batch4_units.py", "test_wiring.py"]
def main():
failed = []
for s in SUITES:
path = os.path.join(HERE, s)
if not os.path.exists(path):
print(f"== 跳过 {s} (文件不存在)")
continue
print(f"\n=== {s} " + "=" * (52 - len(s)))
r = subprocess.run([sys.executable, path], cwd=ROOT)
if r.returncode != 0:
failed.append(s)
print("\n" + "=" * 62)
if failed:
print(f"SUITE FAILED: {', '.join(failed)}")
sys.exit(1)
print("ALL SUITES PASS")
if __name__ == "__main__":
main()