Files
crypto_monitor/tests/test_journal_form_lib.py
T
dekun d3a44b23db Split journal order type from entry reason and fix review edit toggle in embed shell.
Adds order_type to journal uploads, removes legacy swing/trend labels from entry reason options, and ensures review-edit buttons sync when the records tab loads dynamically.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-09 09:27:03 +08:00

64 lines
2.5 KiB
Python

"""journal_form_lib / strategy_trade_labels 下单类型与开仓类型拆分."""
from __future__ import annotations
import unittest
from lib.instance.journal_form_lib import (
journal_entry_reason_valid,
normalize_journal_entry_reason,
)
from lib.strategy.strategy_trade_labels import (
JOURNAL_ORDER_TYPE_OPTIONS,
normalize_journal_order_type,
order_type_from_monitor_type,
)
from lib.trade.entry_model_lib import build_journal_entry_reason_options
class JournalFormLibTests(unittest.TestCase):
def test_journal_entry_reason_excludes_legacy_style_and_strategy(self):
opts = build_journal_entry_reason_options()
self.assertIn("反转/启动A", opts)
self.assertNotIn("趋势单", opts)
self.assertNotIn("波段单", opts)
self.assertNotIn("趋势回调", opts)
self.assertNotIn("顺势加仓", opts)
def test_normalize_journal_entry_reason_rejects_legacy_for_new_submit(self):
opts = build_journal_entry_reason_options()
self.assertEqual(
normalize_journal_entry_reason("趋势单", opts, allow_legacy=False),
"",
)
self.assertEqual(
normalize_journal_entry_reason("趋势回调", opts, allow_legacy=False),
"",
)
def test_normalize_journal_entry_reason_accepts_legacy_when_allowed(self):
opts = build_journal_entry_reason_options()
self.assertEqual(
normalize_journal_entry_reason("趋势单", opts, allow_legacy=True),
"趋势单",
)
def test_order_type_from_monitor_type(self):
self.assertEqual(order_type_from_monitor_type("下单监控"), "下单监控")
self.assertEqual(order_type_from_monitor_type("关键位监控"), "关键位监控")
self.assertEqual(order_type_from_monitor_type("趋势回调"), "趋势回调")
self.assertEqual(order_type_from_monitor_type("顺势加仓"), "顺势加仓")
def test_normalize_journal_order_type(self):
self.assertEqual(normalize_journal_order_type("顺势加仓"), "顺势加仓")
self.assertEqual(normalize_journal_order_type(""), "")
self.assertEqual(len(JOURNAL_ORDER_TYPE_OPTIONS), 4)
def test_journal_entry_reason_valid(self):
opts = build_journal_entry_reason_options()
self.assertTrue(journal_entry_reason_valid("顺势/大分歧A", opts))
self.assertFalse(journal_entry_reason_valid("趋势单", opts))
if __name__ == "__main__":
unittest.main()