blenderpython/test_installation.py

230 lines
6.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SUWood 插件安装测试脚本
用于验证插件是否正确安装和加载
"""
import sys
import os
def test_blender_environment():
"""测试Blender环境"""
print("🔍 测试Blender环境...")
try:
import bpy
print("✅ Blender环境可用")
print(f" Blender版本: {bpy.app.version_string}")
print(f" Python版本: {sys.version}")
return True
except ImportError:
print("❌ Blender环境不可用")
return False
def test_suwood_modules():
"""测试SUWood模块导入"""
print("\n🔍 测试SUWood模块...")
modules_to_test = [
'suw_core',
'suw_menu',
'suw_observer',
'suw_client',
'suw_constants',
'suw_load',
'suw_unit_point_tool',
'suw_unit_face_tool',
'suw_unit_cont_tool',
'suw_zone_div1_tool'
]
success_count = 0
for module_name in modules_to_test:
try:
module = __import__(module_name)
print(f"{module_name} - 导入成功")
success_count += 1
except ImportError as e:
print(f"{module_name} - 导入失败: {e}")
print(f"\n📊 模块测试结果: {success_count}/{len(modules_to_test)} 成功")
return success_count == len(modules_to_test)
def test_addon_registration():
"""测试插件注册"""
print("\n🔍 测试插件注册...")
try:
import bpy
# 检查插件信息
if hasattr(bpy.context, 'preferences'):
addons = bpy.context.preferences.addons
suwood_addon = None
for addon in addons:
if 'suwood' in addon.module.lower():
suwood_addon = addon
break
if suwood_addon:
print("✅ SUWood插件已注册")
print(f" 插件名称: {suwood_addon.module}")
return True
else:
print("⚠️ SUWood插件未找到可能需要手动注册")
return False
else:
print("⚠️ 无法访问Blender偏好设置")
return False
except Exception as e:
print(f"❌ 插件注册测试失败: {e}")
return False
def test_panel_creation():
"""测试面板创建"""
print("\n🔍 测试面板创建...")
try:
import bpy
# 检查面板类是否存在
panel_classes = [
'SUWOOD_PT_main_panel',
'SUWOOD_OT_unit_point_tool',
'SUWOOD_OT_unit_face_tool',
'SUWOOD_OT_delete_unit',
'SUWOOD_OT_zone_div1_tool'
]
success_count = 0
for class_name in panel_classes:
if hasattr(bpy.types, class_name):
print(f"{class_name} - 已注册")
success_count += 1
else:
print(f"{class_name} - 未注册")
print(f"\n📊 面板测试结果: {success_count}/{len(panel_classes)} 成功")
return success_count == len(panel_classes)
except Exception as e:
print(f"❌ 面板测试失败: {e}")
return False
def test_tool_functions():
"""测试工具功能"""
print("\n🔍 测试工具功能...")
try:
# 测试工具函数
from suw_unit_point_tool import create_point_tool
from suw_unit_face_tool import create_face_tool
from suw_zone_div1_tool import create_zone_div1_tool
# 创建工具实例
point_tool = create_point_tool()
face_tool = create_face_tool(1) # 前视图
zone_tool = create_zone_div1_tool()
print("✅ 工具创建成功")
print(f" 点击创体工具: {type(point_tool).__name__}")
print(f" 选面创体工具: {type(face_tool).__name__}")
print(f" 六面切割工具: {type(zone_tool).__name__}")
return True
except Exception as e:
print(f"❌ 工具功能测试失败: {e}")
return False
def test_core_system():
"""测试核心系统"""
print("\n🔍 测试核心系统...")
try:
from suw_core import init_all_managers, get_selection_manager
# 初始化管理器
init_all_managers()
print("✅ 管理器初始化成功")
# 获取选择管理器
selection_manager = get_selection_manager()
if selection_manager:
print("✅ 选择管理器可用")
return True
else:
print("❌ 选择管理器不可用")
return False
except Exception as e:
print(f"❌ 核心系统测试失败: {e}")
return False
def main():
"""主测试函数"""
print("🚀 SUWood 插件安装测试")
print("=" * 50)
# 运行所有测试
tests = [
("Blender环境", test_blender_environment),
("SUWood模块", test_suwood_modules),
("插件注册", test_addon_registration),
("面板创建", test_panel_creation),
("工具功能", test_tool_functions),
("核心系统", test_core_system)
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"{test_name}测试异常: {e}")
results.append((test_name, False))
# 输出测试总结
print("\n" + "=" * 50)
print("📋 测试总结")
print("=" * 50)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "✅ 通过" if result else "❌ 失败"
print(f"{test_name:12} - {status}")
print(f"\n📊 总体结果: {passed}/{total} 测试通过")
if passed == total:
print("\n🎉 恭喜SUWood插件安装成功")
print("📝 使用说明:")
print(" 1. 打开3D视图")
print(" 2. 按N键打开侧边栏")
print(" 3. 点击SUWood标签页")
print(" 4. 开始使用工具")
else:
print("\n⚠️ 部分测试失败,请检查安装")
print("📝 建议:")
print(" 1. 确保Blender版本为3.0+")
print(" 2. 检查插件是否正确安装")
print(" 3. 重启Blender")
print(" 4. 查看控制台错误信息")
if __name__ == "__main__":
main()