From 58eb551898cc0dce33c42300620791339625fd91 Mon Sep 17 00:00:00 2001 From: TPTBusiness Date: Sun, 3 May 2026 11:14:33 +0200 Subject: [PATCH] test: add 4 tests for QuantTrace and QlibQuantHypothesis --- test/qlib/test_quant_proposal.py | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/qlib/test_quant_proposal.py diff --git a/test/qlib/test_quant_proposal.py b/test/qlib/test_quant_proposal.py new file mode 100644 index 00000000..888aff1f --- /dev/null +++ b/test/qlib/test_quant_proposal.py @@ -0,0 +1,58 @@ +"""Tests for quant_proposal — QuantTrace, QlibQuantHypothesis.""" + +from __future__ import annotations + +import sys +from pathlib import Path +from unittest.mock import MagicMock + +import pytest + +PROJECT_ROOT = Path(__file__).parent.parent.parent +sys.path.insert(0, str(PROJECT_ROOT)) + + +class TestQuantTrace: + def test_init_factor_count_zero(self): + from rdagent.scenarios.qlib.proposal.quant_proposal import QuantTrace + trace = QuantTrace(scen=MagicMock()) + assert trace.get_factor_count() == 0 + assert trace.controller is not None + + def test_increment_factor_count(self): + from rdagent.scenarios.qlib.proposal.quant_proposal import QuantTrace + trace = QuantTrace(scen=MagicMock()) + trace.increment_factor_count() + assert trace.get_factor_count() == 1 + trace.increment_factor_count() + assert trace.get_factor_count() == 2 + + +class TestQlibQuantHypothesis: + def test_construction_fields(self): + from rdagent.scenarios.qlib.proposal.quant_proposal import QlibQuantHypothesis + h = QlibQuantHypothesis( + hypothesis="test hypothesis", + reason="test reason", + concise_reason="cr", + concise_observation="co", + concise_justification="cj", + concise_knowledge="ck", + action="factor", + ) + assert h.hypothesis == "test hypothesis" + assert h.reason == "test reason" + assert h.action == "factor" + assert h.concise_reason == "cr" + + def test_str_contains_action(self): + from rdagent.scenarios.qlib.proposal.quant_proposal import QlibQuantHypothesis + h = QlibQuantHypothesis( + hypothesis="h", reason="r", concise_reason="cr", + concise_observation="co", concise_justification="cj", + concise_knowledge="ck", action="model", + ) + s = str(h) + assert "Chosen Action: model" in s + assert "Hypothesis: h" in s + assert "Reason: r" in s