e7f8e9201e
Add an 执行手册 tab that renders docs/交易执行手册-期权与Gate.md as the default strategy view. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from lib.hub.hub_strategy_lib import (
|
|
load_checklist,
|
|
load_strategy_payload,
|
|
strategy_meta_payload,
|
|
build_export_html,
|
|
build_print_html,
|
|
)
|
|
|
|
|
|
class TestHubStrategyLib(unittest.TestCase):
|
|
def test_meta_has_playbook_and_exchanges(self):
|
|
meta = strategy_meta_payload()
|
|
keys = [x["key"] for x in meta["exchanges"]]
|
|
self.assertEqual(keys, ["playbook", "binance", "okx", "gate"])
|
|
|
|
def test_load_playbook_payload(self):
|
|
p = load_strategy_payload("playbook")
|
|
self.assertTrue(p["ok"])
|
|
self.assertEqual(p["label"], "执行手册")
|
|
self.assertIn("交易执行手册", p["md_source"])
|
|
self.assertIn("strategy_html", p)
|
|
self.assertIn("<h2", p["strategy_html"].lower())
|
|
self.assertIn("总原则", p["strategy_html"])
|
|
|
|
def test_load_binance_payload(self):
|
|
p = load_strategy_payload("binance")
|
|
self.assertTrue(p["ok"])
|
|
self.assertIn("strategy_html", p)
|
|
self.assertIn("groups", p["checklist"])
|
|
self.assertIn("<h2", p["strategy_html"].lower())
|
|
|
|
def test_checklist_files_valid_json(self):
|
|
root = Path(__file__).resolve().parent.parent / "docs" / "strategy" / "checklists"
|
|
for name in ("binance", "okx", "gate"):
|
|
data = json.loads((root / f"{name}.json").read_text(encoding="utf-8"))
|
|
self.assertTrue(data.get("groups"))
|
|
|
|
def test_export_html_contains_checklist(self):
|
|
html = build_export_html("gate")
|
|
self.assertIn("Gate", html)
|
|
self.assertIn('class="box"', html)
|
|
self.assertNotIn("☐", html)
|
|
|
|
def test_print_html_doc_and_checklist(self):
|
|
doc = build_print_html("binance", "doc")
|
|
cl = build_print_html("binance", "checklist")
|
|
self.assertIn("window.print", doc)
|
|
self.assertIn("window.print", cl)
|
|
self.assertNotIn("window.close", cl)
|
|
self.assertIn("币安", doc)
|
|
self.assertIn("开仓检查清单", cl)
|
|
self.assertIn('class="box"', cl)
|
|
self.assertIn("本账户仅做多", cl)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|