akg-factor-bridge/test_plan_review_heads.py

44 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""plan_review 三套对照插入两个头两行的单测(注入假读数,需要 pandas,容器里跑)。
跑法:docker exec akg_factor_bridge python3 test_plan_review_heads.py
"""
import sys
import types
# 与 test_market_context.py 同一约定:只给缺席的驱动装最小桩(pandas 要真的,compare_table 返回 DataFrame)。
for _n in ("psycopg", "pymysql", "dotenv"):
if _n not in sys.modules:
try:
__import__(_n)
except ImportError:
sys.modules[_n] = types.ModuleType(_n)
import pandas as pd # noqa: E402
import plan_review # noqa: E402
def main():
calls = []
plan_review._list_reading = lambda tbl, name: f"{name}读数" # noqa: SLF001
plan_review.timing_self_eval = lambda since, until: "择时自评读数"
def fake_head(since, until, *, ref_type, horizon):
calls.append((ref_type, horizon))
return f"{ref_type} 命中率 55%"
plan_review.timing_head_eval = fake_head
tbl = pd.DataFrame([{"名单": "候选单"}])
out = plan_review.compare_table(tbl, "2026-09-01", "2026-09-11")
systems = list(out["系统"])
assert systems == ["选股系统", "择时决策系统", "择时决策系统·五日头", "择时决策系统·二十日头", "PMS 账本"], systems
assert ("pv_h5", 5) in calls and ("pv_h20", 20) in calls, calls
reading = dict(zip(out["系统"], out["读数"]))
assert reading["择时决策系统·五日头"] == "pv_h5 命中率 55%", reading
assert reading["择时决策系统·二十日头"] == "pv_h20 命中率 55%", reading
print("ALL OK — 三套对照多出五日头、二十日头两行,顺序正确,判分种类 pv_h5/pv_h20 与期限 5/20 正确")
if __name__ == "__main__":
main()