172 lines
4.7 KiB
Python
172 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
环境测试脚本 - 检查MetaCore运行环境
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
import subprocess
|
||
|
||
def test_python():
|
||
"""测试Python环境"""
|
||
print("🐍 Python环境检查")
|
||
print(f" Python版本: {sys.version}")
|
||
print(f" Python路径: {sys.executable}")
|
||
print(f" 平台: {sys.platform}")
|
||
|
||
# 检查Python版本
|
||
if sys.version_info < (3, 6):
|
||
print(" ❌ Python版本过低,需要3.6或更高版本")
|
||
return False
|
||
else:
|
||
print(" ✅ Python版本符合要求")
|
||
return True
|
||
|
||
def test_pyqt5():
|
||
"""测试PyQt5"""
|
||
print("\n🎨 PyQt5环境检查")
|
||
try:
|
||
import PyQt5
|
||
print(f" PyQt5版本: {PyQt5.Qt.PYQT_VERSION_STR}")
|
||
print(f" Qt版本: {PyQt5.Qt.QT_VERSION_STR}")
|
||
|
||
# 尝试创建应用程序
|
||
from PyQt5.QtWidgets import QApplication
|
||
app = QApplication([])
|
||
print(" ✅ PyQt5可以正常使用")
|
||
app.quit()
|
||
return True
|
||
|
||
except ImportError as e:
|
||
print(f" ❌ PyQt5未安装: {e}")
|
||
print(" 💡 安装命令: pip install PyQt5")
|
||
return False
|
||
except Exception as e:
|
||
print(f" ❌ PyQt5测试失败: {e}")
|
||
return False
|
||
|
||
def test_project_files():
|
||
"""测试项目文件"""
|
||
print("\n📁 项目文件检查")
|
||
|
||
required_files = [
|
||
'main.py',
|
||
'ui/main_window.py',
|
||
'ui/sidebar.py',
|
||
'ui/project_area.py',
|
||
'ui/project_card.py',
|
||
'data/project_manager.py'
|
||
]
|
||
|
||
missing_files = []
|
||
for file_path in required_files:
|
||
if os.path.exists(file_path):
|
||
print(f" ✅ {file_path}")
|
||
else:
|
||
print(f" ❌ {file_path} (缺失)")
|
||
missing_files.append(file_path)
|
||
|
||
if missing_files:
|
||
print(f" ⚠️ 缺失 {len(missing_files)} 个文件")
|
||
return False
|
||
else:
|
||
print(" ✅ 所有必需文件都存在")
|
||
return True
|
||
|
||
def test_imports():
|
||
"""测试模块导入"""
|
||
print("\n📦 模块导入检查")
|
||
|
||
modules_to_test = [
|
||
('ui.main_window', 'MainWindow'),
|
||
('ui.sidebar', 'Sidebar'),
|
||
('ui.project_area', 'ProjectArea'),
|
||
('ui.project_card', 'ProjectCard'),
|
||
('data.project_manager', 'ProjectManager'),
|
||
]
|
||
|
||
import_errors = []
|
||
for module_name, class_name in modules_to_test:
|
||
try:
|
||
module = __import__(module_name, fromlist=[class_name])
|
||
getattr(module, class_name)
|
||
print(f" ✅ {module_name}.{class_name}")
|
||
except Exception as e:
|
||
print(f" ❌ {module_name}.{class_name}: {e}")
|
||
import_errors.append((module_name, e))
|
||
|
||
if import_errors:
|
||
print(f" ⚠️ {len(import_errors)} 个模块导入失败")
|
||
return False
|
||
else:
|
||
print(" ✅ 所有模块导入成功")
|
||
return True
|
||
|
||
def test_virtual_env():
|
||
"""检查是否在虚拟环境中"""
|
||
print("\n🔧 虚拟环境检查")
|
||
|
||
# 检查是否在虚拟环境中
|
||
in_venv = (
|
||
hasattr(sys, 'real_prefix') or
|
||
(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
|
||
)
|
||
|
||
if in_venv:
|
||
print(" ✅ 当前在虚拟环境中")
|
||
print(f" 环境路径: {sys.prefix}")
|
||
else:
|
||
print(" ⚠️ 当前不在虚拟环境中")
|
||
print(" 💡 建议使用虚拟环境运行项目")
|
||
|
||
return True
|
||
|
||
def main():
|
||
"""主测试函数"""
|
||
print("=" * 50)
|
||
print("🧪 MetaCore环境测试")
|
||
print("=" * 50)
|
||
|
||
tests = [
|
||
test_python,
|
||
test_pyqt5,
|
||
test_project_files,
|
||
test_imports,
|
||
test_virtual_env
|
||
]
|
||
|
||
results = []
|
||
for test_func in tests:
|
||
try:
|
||
result = test_func()
|
||
results.append(result)
|
||
except Exception as e:
|
||
print(f" ❌ 测试失败: {e}")
|
||
results.append(False)
|
||
|
||
print("\n" + "=" * 50)
|
||
print("📊 测试结果汇总")
|
||
print("=" * 50)
|
||
|
||
passed = sum(results)
|
||
total = len(results)
|
||
|
||
if passed == total:
|
||
print(f"🎉 所有测试通过 ({passed}/{total})")
|
||
print("✅ 环境配置正确,可以运行MetaCore!")
|
||
print("\n🚀 运行命令:")
|
||
print(" python main.py")
|
||
else:
|
||
print(f"⚠️ 部分测试失败 ({passed}/{total})")
|
||
print("❌ 请根据上述提示修复问题")
|
||
|
||
if not any(results[:2]): # Python和PyQt5测试失败
|
||
print("\n💡 建议操作:")
|
||
print("1. 确保Python 3.6+已安装")
|
||
print("2. 安装PyQt5: pip install PyQt5")
|
||
print("3. 重新运行测试: python test_environment.py")
|
||
|
||
if __name__ == "__main__":
|
||
main()
|