87 lines
2.0 KiB
Python
87 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test JSON-RPC Registration
|
|
测试JSON-RPC方法注册
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到Python路径
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from python_core.utils.jsonrpc_enhanced import method_registry
|
|
from python_core.scene_detection import SceneDetector
|
|
|
|
|
|
def test_method_registration():
|
|
"""测试方法注册"""
|
|
print("🧪 测试JSON-RPC方法注册...")
|
|
|
|
# 创建检测器并注册方法
|
|
detector = SceneDetector()
|
|
detector.register_jsonrpc_methods()
|
|
|
|
# 检查注册的方法
|
|
print(f"📋 已注册的方法: {list(method_registry.methods.keys())}")
|
|
|
|
# 测试方法调用
|
|
test_request = '''
|
|
{
|
|
"jsonrpc": "2.0",
|
|
"method": "scene.get_video_info",
|
|
"params": {
|
|
"video_path": "assets/1/1752032011698.mp4"
|
|
},
|
|
"id": 1
|
|
}
|
|
'''
|
|
|
|
print("📤 测试方法调用...")
|
|
response = method_registry.handle_request(test_request)
|
|
|
|
if response:
|
|
print("📥 收到响应:")
|
|
print(response)
|
|
else:
|
|
print("📥 收到空响应(异步模式)")
|
|
|
|
return True
|
|
|
|
|
|
def test_direct_method_call():
|
|
"""测试直接方法调用"""
|
|
print("\n🧪 测试直接方法调用...")
|
|
|
|
detector = SceneDetector()
|
|
|
|
# 直接调用方法
|
|
result = detector.jsonrpc_get_video_info("assets/1/1752032011698.mp4")
|
|
|
|
print(f"📋 直接调用结果: {result}")
|
|
|
|
return True
|
|
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("🚀 开始测试JSON-RPC方法注册")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
test_method_registration()
|
|
test_direct_method_call()
|
|
print("\n✅ 所有测试通过")
|
|
return True
|
|
except Exception as e:
|
|
print(f"\n❌ 测试失败: {e}")
|
|
import traceback
|
|
print(f"详细错误: {traceback.format_exc()}")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|