You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
5.3 KiB
194 lines
5.3 KiB
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
MagicWord 0.2.0 版本测试构建脚本
|
|
简化版本用于测试功能完整性
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
from datetime import datetime
|
|
|
|
def test_imports():
|
|
"""测试所有依赖是否可以正常导入"""
|
|
print("测试依赖导入...")
|
|
|
|
required_modules = [
|
|
'PyQt5',
|
|
'requests',
|
|
'bs4',
|
|
'docx',
|
|
'PyPDF2',
|
|
'ebooklib',
|
|
'PIL',
|
|
'chardet'
|
|
]
|
|
|
|
failed_modules = []
|
|
|
|
for module in required_modules:
|
|
try:
|
|
if module == 'bs4':
|
|
import bs4
|
|
elif module == 'docx':
|
|
import docx
|
|
elif module == 'PIL':
|
|
import PIL
|
|
else:
|
|
__import__(module)
|
|
print(f"✓ {module}")
|
|
except ImportError as e:
|
|
print(f"✗ {module}: {e}")
|
|
failed_modules.append(module)
|
|
|
|
if failed_modules:
|
|
print(f"\n导入失败的模块: {', '.join(failed_modules)}")
|
|
return False
|
|
|
|
print("所有依赖导入成功!")
|
|
return True
|
|
|
|
def test_source_files():
|
|
"""测试源代码文件是否存在"""
|
|
print("\n检查源代码文件...")
|
|
|
|
required_files = [
|
|
'src/main.py',
|
|
'src/main_window.py',
|
|
'src/ui/word_style_ui.py',
|
|
'src/file_manager/file_operations.py',
|
|
'src/input_handler/input_processor.py',
|
|
'src/services/network_service.py',
|
|
'resources/icons/app_icon.ico',
|
|
'resources/config/app_settings.json'
|
|
]
|
|
|
|
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"\n缺失的文件: {', '.join(missing_files)}")
|
|
return False
|
|
|
|
print("所有源代码文件检查通过!")
|
|
return True
|
|
|
|
def test_version_info():
|
|
"""测试版本信息"""
|
|
print("\n检查版本信息...")
|
|
|
|
# 检查setup.py
|
|
if os.path.exists('setup.py'):
|
|
with open('setup.py', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
if 'version="0.2.0"' in content:
|
|
print("✓ setup.py 版本号正确")
|
|
else:
|
|
print("✗ setup.py 版本号不正确")
|
|
return False
|
|
|
|
# 检查CHANGELOG.md
|
|
if os.path.exists('CHANGELOG.md'):
|
|
with open('CHANGELOG.md', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
if '0.2.0' in content:
|
|
print("✓ CHANGELOG.md 包含0.2.0版本信息")
|
|
else:
|
|
print("✗ CHANGELOG.md 缺少0.2.0版本信息")
|
|
return False
|
|
|
|
print("版本信息检查通过!")
|
|
return True
|
|
|
|
def test_city_mapping():
|
|
"""测试城市映射功能"""
|
|
print("\n测试城市映射功能...")
|
|
|
|
try:
|
|
# 尝试导入城市映射
|
|
sys.path.append('src')
|
|
from ui.word_style_ui import city_id_map
|
|
|
|
# 检查一些主要城市
|
|
test_cities = [
|
|
('Beijing', '北京'),
|
|
('Shanghai', '上海'),
|
|
('Guangzhou', '广州'),
|
|
('Shenzhen', '深圳'),
|
|
('Chengdu', '成都'),
|
|
('Hangzhou', '杭州')
|
|
]
|
|
|
|
for eng_name, chn_name in test_cities:
|
|
if eng_name in city_id_map:
|
|
mapped_name = city_id_map[eng_name]
|
|
if mapped_name == chn_name:
|
|
print(f"✓ {eng_name} -> {mapped_name}")
|
|
else:
|
|
print(f"⚠ {eng_name} -> {mapped_name} (期望: {chn_name})")
|
|
else:
|
|
print(f"✗ {eng_name} 未找到映射")
|
|
|
|
print(f"城市映射表包含 {len(city_id_map)} 个城市")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"城市映射测试失败: {e}")
|
|
return False
|
|
|
|
def create_test_report():
|
|
"""创建测试报告"""
|
|
print("\n" + "="*60)
|
|
print("MagicWord 0.2.0 版本功能测试报告")
|
|
print("="*60)
|
|
print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
|
|
tests = [
|
|
("依赖导入测试", test_imports),
|
|
("源代码文件检查", test_source_files),
|
|
("版本信息检查", test_version_info),
|
|
("城市映射功能测试", test_city_mapping)
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test_name, test_func in tests:
|
|
print(f"\n[{test_name}]")
|
|
if test_func():
|
|
passed += 1
|
|
print(f"✓ {test_name} 通过")
|
|
else:
|
|
print(f"✗ {test_name} 失败")
|
|
|
|
print(f"\n测试结果: {passed}/{total} 通过")
|
|
|
|
if passed == total:
|
|
print("\n✓ 所有测试通过! 版本准备就绪")
|
|
return True
|
|
else:
|
|
print(f"\n✗ {total - passed} 个测试失败, 需要修复")
|
|
return False
|
|
|
|
def main():
|
|
"""主函数"""
|
|
success = create_test_report()
|
|
|
|
if success:
|
|
print("\n建议下一步:")
|
|
print("1. 运行应用进行手动测试")
|
|
print("2. 创建发布包")
|
|
else:
|
|
print("\n请先修复测试中发现的问题")
|
|
|
|
return 0 if success else 1
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |