init
This commit is contained in:
+33
-17
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Basic tests for the LangChain + LangGraph scaffolding
|
||||
LangChain + LangGraph 脚手架基础测试
|
||||
"""
|
||||
|
||||
import unittest
|
||||
@@ -8,18 +8,36 @@ import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
config_path = os.path.join(os.path.dirname(__file__), '..', 'config', 'config.ini')
|
||||
if not os.path.exists(config_path):
|
||||
with open(config_path, 'w') as f:
|
||||
f.write("""
|
||||
[General]
|
||||
DEFAULT_MODEL_SECTION = gpt-4o
|
||||
MAX_RETRIES = 1
|
||||
TIMEOUT = 10
|
||||
|
||||
[gpt-4o]
|
||||
MODEL_NAME = gpt-4o
|
||||
OPENAI_API_KEY = your_openai_api_key_here
|
||||
|
||||
[gpt-3.5-turbo]
|
||||
MODEL_NAME = gpt-3.5-turbo
|
||||
OPENAI_API_KEY = your_openai_api_key_here
|
||||
""")
|
||||
|
||||
from workflows.workflow_manager import WorkflowManager, WorkflowType
|
||||
|
||||
|
||||
class TestWorkflowManager(unittest.TestCase):
|
||||
"""Test WorkflowManager functionality"""
|
||||
"""测试 WorkflowManager 功能"""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test fixtures"""
|
||||
"""设置测试夹具"""
|
||||
self.manager = WorkflowManager()
|
||||
|
||||
def test_get_available_workflows(self):
|
||||
"""Test that available workflows are returned"""
|
||||
"""测试可用工作流返回"""
|
||||
workflows = self.manager.get_available_workflows()
|
||||
self.assertIsInstance(workflows, list)
|
||||
self.assertGreater(len(workflows), 0)
|
||||
@@ -27,7 +45,7 @@ class TestWorkflowManager(unittest.TestCase):
|
||||
self.assertIn("tool_using", workflows)
|
||||
|
||||
def test_get_workflow(self):
|
||||
"""Test getting workflow instances"""
|
||||
"""测试获取工作流实例"""
|
||||
conversation_workflow = self.manager.get_workflow(WorkflowType.CONVERSATION)
|
||||
self.assertIsNotNone(conversation_workflow)
|
||||
|
||||
@@ -35,8 +53,8 @@ class TestWorkflowManager(unittest.TestCase):
|
||||
self.assertIsNotNone(tool_workflow)
|
||||
|
||||
def test_session_management(self):
|
||||
"""Test session creation and retrieval"""
|
||||
# Execute a workflow to create a session
|
||||
"""测试会话创建与获取"""
|
||||
# 执行工作流以创建会话
|
||||
result = self.manager.execute_workflow(
|
||||
WorkflowType.CONVERSATION,
|
||||
"Hello, test session"
|
||||
@@ -45,23 +63,21 @@ class TestWorkflowManager(unittest.TestCase):
|
||||
session_id = result["session_id"]
|
||||
self.assertIsNotNone(session_id)
|
||||
|
||||
# Test session info retrieval
|
||||
# 测试会话信息获取
|
||||
session_info = self.manager.get_session_info(session_id)
|
||||
self.assertIsNotNone(session_info)
|
||||
self.assertEqual(session_info["workflow_type"], WorkflowType.CONVERSATION)
|
||||
|
||||
|
||||
class TestConfiguration(unittest.TestCase):
|
||||
"""Test configuration validation"""
|
||||
"""测试配置校验"""
|
||||
|
||||
def test_config_import(self):
|
||||
"""Test that configuration can be imported"""
|
||||
try:
|
||||
from config import Config
|
||||
# This should not raise an exception if .env file exists with valid API key
|
||||
self.assertTrue(hasattr(Config, 'OPENAI_API_KEY'))
|
||||
except ImportError:
|
||||
self.fail("Could not import config module")
|
||||
def test_config_loading(self):
|
||||
"""测试能从 config.ini 加载配置"""
|
||||
from config import Config
|
||||
model_config = Config.get_model_config()
|
||||
self.assertIn('model', model_config)
|
||||
self.assertIn('api_key', model_config)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user