test_example.py•1.9 kB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
六壬MCP工具测试示例
"""
from liuren_mcp import LiuRenMCP
import json
def test_current_time():
"""测试当前时间六壬盘"""
print("=== 测试当前时间六壬盘 ===")
tool = LiuRenMCP()
result = tool.get_current_liuren_pan()
if "error" in result:
print(f"❌ 获取失败: {result['error']}")
return False
print("✅ 获取成功!")
print(json.dumps(result, ensure_ascii=False, indent=2))
return True
def test_specified_time():
"""测试指定时间六壬盘"""
print("\n=== 测试指定时间六壬盘 ===")
tool = LiuRenMCP()
result = tool.get_liuren_pan(year=2024, month=8, day=15, hour=14, minute=30)
if "error" in result:
print(f"❌ 获取失败: {result['error']}")
return False
print("✅ 获取成功!")
print(json.dumps(result, ensure_ascii=False, indent=2))
return True
def test_partial_time():
"""测试部分指定时间六壬盘"""
print("\n=== 测试部分指定时间六壬盘 ===")
tool = LiuRenMCP()
result = tool.get_liuren_pan(year=2024, month=8, day=15)
if "error" in result:
print(f"❌ 获取失败: {result['error']}")
return False
print("✅ 获取成功!")
print(json.dumps(result, ensure_ascii=False, indent=2))
return True
if __name__ == "__main__":
print("六壬MCP工具测试")
print("=" * 50)
success_count = 0
total_tests = 3
if test_current_time():
success_count += 1
if test_specified_time():
success_count += 1
if test_partial_time():
success_count += 1
print("\n" + "=" * 50)
print(f"测试完成: {success_count}/{total_tests} 通过")
if success_count == total_tests:
print("🎉 所有测试通过!")
else:
print("⚠️ 部分测试失败")