init
This commit is contained in:
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""测试模块"""
|
||||
41
tests/test_helpers.py
Normal file
41
tests/test_helpers.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""测试辅助函数"""
|
||||
|
||||
import pytest
|
||||
from njupt_mcp.utils.helpers import format_json, parse_semester, validate_student_id
|
||||
|
||||
|
||||
def test_format_json():
|
||||
"""测试 JSON 格式化"""
|
||||
data = {"name": "测试", "value": 123}
|
||||
result = format_json(data)
|
||||
assert '"name": "测试"' in result
|
||||
assert '"value": 123' in result
|
||||
|
||||
|
||||
def test_parse_semester_valid():
|
||||
"""测试学期解析 - 有效格式"""
|
||||
result = parse_semester("2024-2025-1")
|
||||
assert result == ("2024", "2025", 1)
|
||||
|
||||
result = parse_semester("2023-2024-2")
|
||||
assert result == ("2023", "2024", 2)
|
||||
|
||||
|
||||
def test_parse_semester_invalid():
|
||||
"""测试学期解析 - 无效格式"""
|
||||
assert parse_semester("2024-2025") is None
|
||||
assert parse_semester("invalid") is None
|
||||
assert parse_semester("") is None
|
||||
|
||||
|
||||
def test_validate_student_id_valid():
|
||||
"""测试学号验证 - 有效格式"""
|
||||
assert validate_student_id("B21010101") is True
|
||||
assert validate_student_id("M21010101") is True
|
||||
|
||||
|
||||
def test_validate_student_id_invalid():
|
||||
"""测试学号验证 - 无效格式"""
|
||||
assert validate_student_id("12345678") is False
|
||||
assert validate_student_id("B210101") is False
|
||||
assert validate_student_id("") is False
|
||||
24
tests/test_server.py
Normal file
24
tests/test_server.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""测试 MCP Server"""
|
||||
|
||||
import pytest
|
||||
from njupt_mcp.server import mcp
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_course():
|
||||
"""测试课程搜索工具"""
|
||||
from njupt_mcp.server import search_course
|
||||
|
||||
result = await search_course("数据结构", limit=2)
|
||||
assert "CS2101" in result
|
||||
assert "数据结构" in result
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_campus_info():
|
||||
"""测试校园信息工具"""
|
||||
from njupt_mcp.server import get_campus_info
|
||||
|
||||
result = await get_campus_info("overview")
|
||||
assert "南京邮电大学" in result
|
||||
assert "NJUPT" in result
|
||||
Reference in New Issue
Block a user