46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
"""review_latest 只读读数单测(临时目录,不连库、不连接口)。
|
||
|
||
跑法:python3 test_review_latest.py 或 docker exec akg_factor_bridge python3 test_review_latest.py
|
||
"""
|
||
import os
|
||
import tempfile
|
||
|
||
import review_latest as R
|
||
|
||
|
||
def _write(d, name, text):
|
||
with open(os.path.join(d, name), "w", encoding="utf-8") as f:
|
||
f.write(text)
|
||
|
||
|
||
def main():
|
||
with tempfile.TemporaryDirectory() as d:
|
||
_write(d, "复盘_2026-09-11_next_close.md",
|
||
"标题\n公司质地=好 3 只\n五日头 命中率 60%\n二十日头 本期无判分记录\n")
|
||
_write(d, "复盘_2026-09-18_next_close.md",
|
||
"# 最新周报\n公司质地=好 4 只\n五日头 命中率 62%\n二十日头 本期无判分记录\n正文\n")
|
||
_write(d, "复盘_2026-09-18_signal_close.md", "别的 start 不该被选\n")
|
||
|
||
rep = R.latest_report(d)
|
||
assert rep["date"] == "2026-09-18", rep
|
||
assert rep["file"] == "复盘_2026-09-18_next_close.md", "取最新一份 next_close"
|
||
|
||
pl = R.payload(d)
|
||
assert pl["date"] == "2026-09-18"
|
||
assert pl["size"] > 0
|
||
assert pl["head"][0] == "# 最新周报", "前二十行含首行"
|
||
assert len(pl["head"]) <= 20
|
||
mc = pl["marker_counts"]
|
||
assert mc["公司质地="] == 1, mc
|
||
assert mc["五日头"] == 1 and mc["二十日头"] == 1, mc
|
||
|
||
with tempfile.TemporaryDirectory() as empty:
|
||
assert R.latest_report(empty) is None, "无周报返回 None"
|
||
assert R.payload(empty) is None
|
||
assert R.latest_report("/no/such/dir/xxx") is None, "目录不存在不炸"
|
||
print("ALL OK — 取最新一份 next_close / 前二十行 / 三个标记行计数 / 无周报返回 None / 目录不存在不炸")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|