| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- """
- 运行所有重构测试
- 这个脚本会依次运行所有测试文件,并生成测试报告
- """
- import subprocess
- import sys
- from pathlib import Path
- from datetime import datetime
- def run_test(test_file, description):
- """运行单个测试文件"""
- print("\n" + "=" * 80)
- print(f"运行测试: {description}")
- print(f"文件: {test_file}")
- print("=" * 80)
- print()
- try:
- result = subprocess.run(
- [sys.executable, test_file],
- capture_output=True,
- text=True,
- timeout=30
- )
- print(result.stdout)
- if result.returncode == 0:
- print(f"\n✅ {description} - 测试通过")
- return True
- else:
- print(f"\n❌ {description} - 测试失败")
- if result.stderr:
- print("错误信息:")
- print(result.stderr)
- return False
- except subprocess.TimeoutExpired:
- print(f"\n⏱️ {description} - 测试超时")
- return False
- except Exception as e:
- print(f"\n❌ {description} - 运行出错: {e}")
- return False
- def main():
- """运行所有测试"""
- print("\n" + "🧪" * 40)
- print("重构功能测试套件")
- print(f"开始时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
- print("🧪" * 40)
- examples_dir = Path(__file__).parent
- # 定义测试列表
- tests = [
- (examples_dir / "test_goal_model.py", "Goal 模型功能测试"),
- (examples_dir / "test_goal_tool.py", "Goal 工具功能测试"),
- (examples_dir / "test_subagent_tool.py", "SubAgent 工具功能测试"),
- ]
- # 运行所有测试
- results = []
- for test_file, description in tests:
- if not test_file.exists():
- print(f"\n⚠️ 测试文件不存在: {test_file}")
- results.append((description, False))
- continue
- success = run_test(test_file, description)
- results.append((description, success))
- # 生成测试报告
- print("\n" + "=" * 80)
- print("测试报告")
- print("=" * 80)
- print()
- passed = sum(1 for _, success in results if success)
- total = len(results)
- print(f"总测试数: {total}")
- print(f"通过: {passed}")
- print(f"失败: {total - passed}")
- print()
- print("详细结果:")
- for description, success in results:
- status = "✅ 通过" if success else "❌ 失败"
- print(f" {status} - {description}")
- print()
- print("=" * 80)
- if passed == total:
- print("🎉 所有测试通过!")
- print("=" * 80)
- return 0
- else:
- print(f"⚠️ {total - passed} 个测试失败")
- print("=" * 80)
- return 1
- if __name__ == "__main__":
- exit_code = main()
- sys.exit(exit_code)
|