"""服务器主函数测试."""
import pytest
import asyncio
from unittest.mock import Mock, MagicMock, patch, AsyncMock
from src.server import create_server, main
class TestServerMainFunction:
"""服务器主函数测试类."""
@pytest.fixture
def server(self):
"""创建服务器实例."""
return create_server()
@pytest.mark.asyncio
async def test_create_server_returns_server(self, server):
"""测试 create_server 返回服务器实例."""
assert server is not None
assert hasattr(server, 'list_tools')
assert hasattr(server, 'call_tool')
assert hasattr(server, 'list_resources')
assert hasattr(server, 'read_resource')
assert hasattr(server, 'list_prompts')
assert hasattr(server, 'get_prompt')
@pytest.mark.asyncio
async def test_create_server_initialization(self, server):
"""测试服务器初始化."""
# 验证服务器已正确初始化
assert server is not None
# 验证服务器有必要的属性
assert hasattr(server, 'run')
assert hasattr(server, 'create_initialization_options')
@pytest.mark.asyncio
async def test_main_function_exists(self):
"""测试主函数存在."""
assert main is not None
assert callable(main)
@pytest.mark.asyncio
async def test_main_function_async(self):
"""测试主函数是异步的."""
import inspect
assert inspect.iscoroutinefunction(main)
@pytest.mark.asyncio
async def test_server_initialization_options(self, server):
"""测试服务器初始化选项."""
# 验证可以创建初始化选项
try:
options = server.create_initialization_options()
# 初始化选项可能为 None 或字典
assert options is None or isinstance(options, dict)
except Exception:
# 如果方法不存在或抛出异常,这是可以接受的
pass