- Added new endpoints to the analyst API for managing assets, including `GET /assets` to list assets and `POST /assets/{kind}/{asset_id}/publish` to publish assets.
- Introduced `DictAmbiguityCheckRequest` schema for checking metric ambiguities, enhancing the analyst's ability to clarify definitions and aliases.
- Implemented `detect_dict_ambiguity` function to analyze potential ambiguities in metrics, providing structured feedback for users.
- Updated `AnalystAgent` to support the new asset management functionalities and ambiguity detection logic, improving overall user experience.
- Enhanced existing schemas and services to accommodate new features, ensuring robust data handling and validation.
This update significantly improves the analyst API's capabilities, allowing for better asset management and clarity in metric definitions.
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
"""dict_service 口径字典单元测试。"""
|
|
import unittest
|
|
|
|
from app.service.dict_service import Ambiguity, Metric, default_registry, merge_registries
|
|
|
|
|
|
class TestDictService(unittest.TestCase):
|
|
def setUp(self):
|
|
self.reg = default_registry()
|
|
|
|
def test_resolve_unambiguous(self):
|
|
m = self.reg.resolve("持仓规模")
|
|
self.assertIsInstance(m, Metric)
|
|
self.assertEqual(m.key, "holding_scale")
|
|
|
|
def test_resolve_ambiguous(self):
|
|
m = self.reg.resolve("规模")
|
|
self.assertIsInstance(m, Ambiguity)
|
|
self.assertEqual(len(m.candidates), 2)
|
|
|
|
def test_resolve_missing(self):
|
|
self.assertIsNone(self.reg.resolve("不存在的指标"))
|
|
|
|
def test_alias_match(self):
|
|
m = self.reg.resolve("市值")
|
|
self.assertIsInstance(m, Metric)
|
|
self.assertEqual(m.key, "holding_scale")
|
|
|
|
def test_trade_flow_ambiguous(self):
|
|
m = self.reg.resolve("交易流水")
|
|
self.assertIsInstance(m, Ambiguity)
|
|
self.assertEqual(len(m.candidates), 2)
|
|
keys = sorted(c.key for c in m.candidates)
|
|
self.assertEqual(keys, ["trade_flow_amount", "trade_flow_count"])
|
|
|
|
def test_trade_flow_amount_unambiguous(self):
|
|
m = self.reg.resolve("流水金额")
|
|
self.assertIsInstance(m, Metric)
|
|
self.assertEqual(m.key, "trade_flow_amount")
|
|
|
|
def test_trade_flow_count_unambiguous(self):
|
|
m = self.reg.resolve("流水笔数")
|
|
self.assertIsInstance(m, Metric)
|
|
self.assertEqual(m.key, "trade_flow_count")
|
|
|
|
def test_merge_registries_overlays_by_key(self):
|
|
base = default_registry()
|
|
overlay = [
|
|
Metric(
|
|
"holding_scale",
|
|
"持仓规模(库)",
|
|
["规模", "市值", "持仓市值"],
|
|
"来自 DB 的定义",
|
|
"元",
|
|
"as_of",
|
|
),
|
|
]
|
|
merged = merge_registries(base, overlay)
|
|
keys = {m.key: m for m in merged.all()}
|
|
self.assertEqual(keys["holding_scale"].definition, "来自 DB 的定义")
|
|
self.assertEqual(keys["holding_scale"].name, "持仓规模(库)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|