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.
Curriculum_Design/test_build.py

269 lines
7.8 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MagicWord 0.2.1 版本测试构建脚本
简化版本用于测试功能完整性
"""
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.1"' 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.1' in content:
print("✓ CHANGELOG.md 包含0.2.1版本信息")
else:
print("✗ CHANGELOG.md 缺少0.2.1版本信息")
return False
print("版本信息检查通过!")
return True
def test_city_mapping():
"""测试城市映射功能"""
print("\n测试城市映射功能...")
try:
# 直接定义城市映射表进行测试
city_id_map = {
# 主要城市中文映射
'北京': '101010100',
'上海': '101020100',
'广州': '101280101',
'深圳': '101280601',
'杭州': '101210101',
'南京': '101190101',
'成都': '101270101',
'武汉': '101200101',
'西安': '101110101',
'重庆': '101040100',
'天津': '101030100',
'苏州': '101190401',
'青岛': '101120201',
'大连': '101070201',
'沈阳': '101070101',
'哈尔滨': '101050101',
'长春': '101060101',
'石家庄': '101090101',
'太原': '101100101',
'郑州': '101180101',
'济南': '101120101',
'合肥': '101220101',
'南昌': '101240101',
'长沙': '101250101',
'福州': '101230101',
'厦门': '101230201',
'南宁': '101300101',
'海口': '101310101',
'贵阳': '101260101',
'昆明': '101290101',
'拉萨': '101140101',
'兰州': '101160101',
'西宁': '101150101',
'银川': '101170101',
'乌鲁木齐': '101130101',
'呼和浩特': '101080101',
# 英文城市名映射到中文
'Beijing': '北京',
'Shanghai': '上海',
'Guangzhou': '广州',
'Shenzhen': '深圳',
'Hangzhou': '杭州',
'Nanjing': '南京',
'Chengdu': '成都',
'Wuhan': '武汉',
'Xian': '西安',
'Chongqing': '重庆',
'Tianjin': '天津',
'Suzhou': '苏州',
'Qingdao': '青岛',
'Dalian': '大连',
'Shenyang': '沈阳',
'Harbin': '哈尔滨',
'Changchun': '长春',
'Shijiazhuang': '石家庄',
'Taiyuan': '太原',
'Zhengzhou': '郑州',
'Jinan': '济南',
'Hefei': '合肥',
'Nanchang': '南昌',
'Changsha': '长沙',
'Fuzhou': '福州',
'Xiamen': '厦门',
'Nanning': '南宁',
'Haikou': '海口',
'Guiyang': '贵阳',
'Kunming': '昆明',
'Lhasa': '拉萨',
'Lanzhou': '兰州',
'Xining': '西宁',
'Yinchuan': '银川',
'Urumqi': '乌鲁木齐',
'Hohhot': '呼和浩特'
}
# 检查一些主要城市
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.1 版本功能测试报告")
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())