feat(ui): 添加AI协作页签
新增AI协作功能模块,并在主界面中添加了对应的页签。 更新了OpenBB集成文档的路径,将其从单独的Markdown文件迁移到目录结构中。 为项目添加了新的测试依赖,包括pytest相关工具、locust和memory-profiler等。
This commit is contained in:
24
tests/immortal_tests/test_cultural_accuracy.py
Normal file
24
tests/immortal_tests/test_cultural_accuracy.py
Normal file
@@ -0,0 +1,24 @@
|
||||
class TestCulturalAccuracy:
|
||||
"""文化准确性测试"""
|
||||
|
||||
def test_immortal_characteristics(self):
|
||||
"""验证八仙特征的准确性"""
|
||||
# immortals = get_immortal_configs()
|
||||
#
|
||||
# # 验证吕洞宾的技术分析特色
|
||||
# assert immortals['吕洞宾'].specialty == 'technical_analysis'
|
||||
# assert immortals['吕洞宾'].element == '乾'
|
||||
#
|
||||
# # 验证何仙姑的风险控制特色
|
||||
# assert immortals['何仙姑'].specialty == 'risk_metrics'
|
||||
# assert immortals['何仙姑'].element == '坤'
|
||||
pass
|
||||
|
||||
def test_debate_cultural_context(self):
|
||||
"""验证辩论的文化背景准确性"""
|
||||
# debate = create_test_debate('AAPL')
|
||||
#
|
||||
# # 确保辩论遵循稷下学宫的传统
|
||||
# assert 'jixia' in debate.context
|
||||
# assert len(debate.participants) == 8 # 八仙
|
||||
pass
|
||||
3
tests/immortal_tests/test_debate_data_quality.py
Normal file
3
tests/immortal_tests/test_debate_data_quality.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class TestDebateDataQuality:
|
||||
"""辩论数据质量测试"""
|
||||
pass
|
||||
14
tests/immortal_tests/test_immortal_data_routing.py
Normal file
14
tests/immortal_tests/test_immortal_data_routing.py
Normal file
@@ -0,0 +1,14 @@
|
||||
class TestImmortalDataRouting:
|
||||
"""八仙数据路由测试"""
|
||||
|
||||
def test_lv_dongbin_technical_analysis(self):
|
||||
"""测试吕洞宾的技术分析数据获取"""
|
||||
pass
|
||||
|
||||
def test_he_xiangu_risk_metrics(self):
|
||||
"""测试何仙姑的风险指标数据"""
|
||||
pass
|
||||
|
||||
def test_immortal_data_consistency(self):
|
||||
"""测试八仙数据的一致性"""
|
||||
pass
|
||||
3
tests/immortal_tests/test_immortal_preferences.py
Normal file
3
tests/immortal_tests/test_immortal_preferences.py
Normal file
@@ -0,0 +1,3 @@
|
||||
class TestImmortalPreferences:
|
||||
"""八仙偏好测试"""
|
||||
pass
|
||||
62
tests/openbb_integration/test_openbb_integration.py
Normal file
62
tests/openbb_integration/test_openbb_integration.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import pytest
|
||||
from unittest import mock
|
||||
from src.jixia.engines.openbb_stock_data import get_stock_data
|
||||
from types import SimpleNamespace
|
||||
|
||||
class TestOpenBBIntegration:
|
||||
"""OpenBB集成测试套件"""
|
||||
|
||||
def test_stock_data_retrieval(self):
|
||||
"""测试股票数据成功获取"""
|
||||
# 创建一个模拟的'openbb'模块
|
||||
mock_openbb_module = mock.MagicMock()
|
||||
# 在该模块上创建一个模拟的'obb'属性
|
||||
mock_obb_object = mock.MagicMock()
|
||||
mock_openbb_module.obb = mock_obb_object
|
||||
|
||||
# 配置模拟的obb对象的返回值
|
||||
mock_data = [
|
||||
SimpleNamespace(date='2023-01-01', open=100, high=110, low=90, close=105, volume=10000),
|
||||
SimpleNamespace(date='2023-01-02', open=105, high=115, low=102, close=112, volume=12000)
|
||||
]
|
||||
mock_obb_object.equity.price.historical.return_value = SimpleNamespace(results=mock_data)
|
||||
|
||||
# 使用patch.dict来模拟openbb模块的导入
|
||||
with mock.patch.dict('sys.modules', {'openbb': mock_openbb_module}):
|
||||
data = get_stock_data('AAPL')
|
||||
|
||||
# 断言
|
||||
assert data is not None
|
||||
assert len(data) == 2
|
||||
assert data[0].close == 105
|
||||
mock_obb_object.equity.price.historical.assert_called_once()
|
||||
|
||||
def test_stock_data_handles_api_error(self):
|
||||
"""测试当OpenBB API未返回有效数据时的情况"""
|
||||
mock_openbb_module = mock.MagicMock()
|
||||
mock_obb_object = mock.MagicMock()
|
||||
mock_openbb_module.obb = mock_obb_object
|
||||
|
||||
# 配置模拟的obb对象以返回没有结果的情况
|
||||
mock_obb_object.equity.price.historical.return_value = SimpleNamespace(results=None)
|
||||
|
||||
with mock.patch.dict('sys.modules', {'openbb': mock_openbb_module}):
|
||||
data = get_stock_data('FAIL')
|
||||
|
||||
# 断言
|
||||
assert data is None
|
||||
mock_obb_object.equity.price.historical.assert_called_once_with(
|
||||
symbol='FAIL',
|
||||
provider='yfinance',
|
||||
start_date=mock.ANY,
|
||||
end_date=mock.ANY
|
||||
)
|
||||
|
||||
def test_stock_data_handles_import_error(self):
|
||||
"""测试openbb库不可用时的降级行为"""
|
||||
# 模拟sys.modules中没有openbb
|
||||
with mock.patch.dict('sys.modules', {'openbb': None}):
|
||||
data = get_stock_data('NOBB')
|
||||
|
||||
# 断言
|
||||
assert data is None
|
||||
Reference in New Issue
Block a user