test_reminder.py•2.58 kB
# test_reminder.py
import subprocess
import json
import sys
def test_create_reminder():
"""
测试创建提醒事项功能
"""
# 测试用例
test_cases = [
{
"title": "测试提醒事项1",
"notes": "这是一个测试提醒事项,无日期",
"date": "",
"time": ""
},
{
"title": "测试提醒事项2",
"notes": "这是一个带日期的测试提醒事项",
"date": "2025-05-20",
"time": ""
},
{
"title": "测试提醒事项3",
"notes": "这是一个带日期和时间的测试提醒事项",
"date": "2025-05-21",
"time": "14:30:00"
}
]
print("开始测试创建提醒事项功能...")
for i, test_case in enumerate(test_cases):
print(f"\n测试用例 {i+1}: {test_case['title']}")
# 构建 JSON 请求
request = {
"jsonrpc": "2.0",
"id": i+1,
"method": "tool",
"params": {
"name": "create_reminder",
"parameters": test_case
}
}
# 将请求转换为 JSON 字符串
request_str = json.dumps(request)
# 启动 reminder.py 进程
process = subprocess.Popen(
['python', 'reminder.py'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# 发送请求并获取响应
stdout, stderr = process.communicate(input=request_str)
# 检查是否有错误
if stderr:
print(f"错误: {stderr}")
continue
# 解析响应
try:
response = json.loads(stdout)
print(f"响应: {json.dumps(response, ensure_ascii=False, indent=2)}")
# 检查响应是否成功
if 'result' in response and response['result'].get('success'):
print(f"✅ 测试通过: {test_case['title']} 创建成功")
else:
print(f"❌ 测试失败: {test_case['title']} 创建失败")
if 'result' in response:
print(f"失败原因: {response['result'].get('message', '未知错误')}")
except json.JSONDecodeError as e:
print(f"解析响应失败: {e}")
print(f"原始响应: {stdout}")
if __name__ == "__main__":
test_create_reminder()