重构: 迁移后端代码到 app 目录,前端移动到 WebUI,添加完整测试套件
主要变更: - 后端代码从根目录迁移到 app/ 目录 - 前端代码从 frontend/ 重命名为 WebUI/ - 更新所有导入路径以适配新结构 - 提取公共 API 响应函数到 app/api/common.py - 精简验证器服务代码 - 更新启动脚本和文档 测试: - 新增完整测试套件 (tests/) - 单元测试: 模型、仓库层 - 集成测试: 覆盖所有 22+ API 端点 - E2E 测试: 4个完整工作流场景 - 添加 pytest 配置和测试运行脚本
This commit is contained in:
89
tests/run_tests.py
Normal file
89
tests/run_tests.py
Normal file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python
|
||||
"""测试运行脚本 - 方便运行各种类型的测试"""
|
||||
import sys
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
|
||||
def run_command(cmd, description):
|
||||
"""运行命令并打印结果"""
|
||||
print(f"\n{'='*60}")
|
||||
print(f"运行: {description}")
|
||||
print(f"命令: {' '.join(cmd)}")
|
||||
print('='*60)
|
||||
|
||||
result = subprocess.run(cmd, shell=False)
|
||||
return result.returncode
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='运行 ProxyPool 测试')
|
||||
parser.add_argument(
|
||||
'type',
|
||||
nargs='?',
|
||||
default='all',
|
||||
choices=['all', 'unit', 'integration', 'e2e', 'coverage'],
|
||||
help='测试类型 (默认: all)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-v', '--verbose',
|
||||
action='store_true',
|
||||
help='详细输出'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-k',
|
||||
metavar='EXPRESSION',
|
||||
help='只运行匹配表达式的测试 (pytest -k 选项)'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# 基础命令
|
||||
base_cmd = [sys.executable, "-m", "pytest"]
|
||||
|
||||
if args.verbose:
|
||||
base_cmd.append("-v")
|
||||
|
||||
if args.k:
|
||||
base_cmd.extend(["-k", args.k])
|
||||
|
||||
exit_code = 0
|
||||
|
||||
if args.type == 'all':
|
||||
exit_code = run_command(
|
||||
base_cmd + ["tests/"],
|
||||
"所有测试"
|
||||
)
|
||||
elif args.type == 'unit':
|
||||
exit_code = run_command(
|
||||
base_cmd + ["tests/unit/"],
|
||||
"单元测试"
|
||||
)
|
||||
elif args.type == 'integration':
|
||||
exit_code = run_command(
|
||||
base_cmd + ["tests/integration/"],
|
||||
"集成测试"
|
||||
)
|
||||
elif args.type == 'e2e':
|
||||
exit_code = run_command(
|
||||
base_cmd + ["tests/e2e/"],
|
||||
"端到端测试"
|
||||
)
|
||||
elif args.type == 'coverage':
|
||||
exit_code = run_command(
|
||||
[sys.executable, "-m", "pytest", "tests/", "--cov=app", "--cov-report=html", "--cov-report=term"] + (["-v"] if args.verbose else []),
|
||||
"覆盖率测试"
|
||||
)
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
if exit_code == 0:
|
||||
print("✅ 所有测试通过!")
|
||||
else:
|
||||
print(f"❌ 测试失败 (退出码: {exit_code})")
|
||||
print('='*60)
|
||||
|
||||
return exit_code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user