test_how_decode_v9.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """
  2. HOW解构V9测试脚本
  3. 测试集:从三个账号各选2个帖子,共6个测试用例
  4. """
  5. import asyncio
  6. import sys
  7. import os
  8. # 添加当前目录到path
  9. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  10. from how_decode_v9_point_dependency import main
  11. # 测试数据集:每个账号选2个帖子
  12. TEST_CASES = [
  13. # 阿里多多酱(宠物类账号)
  14. {
  15. "account": "阿里多多酱",
  16. "files": [
  17. "examples_new/阿里多多酱/output/685b593800000000120141d3_20251104_111017.json",
  18. "examples_new/阿里多多酱/output/6865e3ac00000000100251b6_20251104_111021.json",
  19. ]
  20. },
  21. # 白流苏(美甲类账号)
  22. {
  23. "account": "白流苏",
  24. "files": [
  25. "examples_new/白流苏/output/682c53fd000000000303c64f_20251104_112822.json",
  26. "examples_new/白流苏/output/6839827d0000000003039f7e_20251104_112821.json",
  27. ]
  28. },
  29. # 摸鱼阿希
  30. {
  31. "account": "摸鱼阿希",
  32. "files": [
  33. "examples_new/摸鱼阿希/output/61bdc28b0000000001024896_20251104_132959.json",
  34. "examples_new/摸鱼阿希/output/66619827000000000600486f_20251104_133004.json",
  35. ]
  36. }
  37. ]
  38. async def run_test_case(file_path: str, case_num: int, total: int):
  39. """运行单个测试用例"""
  40. print("\n" + "="*100)
  41. print(f"测试用例 {case_num}/{total}: {file_path}")
  42. print("="*100)
  43. # 临时修改sys.argv来模拟命令行参数
  44. original_argv = sys.argv.copy()
  45. sys.argv = ["test_script", file_path]
  46. try:
  47. from lib.my_trace import set_trace
  48. current_time, log_url = set_trace()
  49. from agents import trace
  50. with trace(f"test case {case_num}"):
  51. await main(current_time, log_url)
  52. print(f"\n✅ 测试用例 {case_num} 完成")
  53. except Exception as e:
  54. print(f"\n❌ 测试用例 {case_num} 失败: {e}")
  55. import traceback
  56. traceback.print_exc()
  57. finally:
  58. # 恢复原始参数
  59. sys.argv = original_argv
  60. async def run_all_tests():
  61. """运行所有测试用例"""
  62. all_files = []
  63. # 收集所有测试文件
  64. for account_data in TEST_CASES:
  65. account = account_data["account"]
  66. for file_path in account_data["files"]:
  67. all_files.append((account, file_path))
  68. total = len(all_files)
  69. print(f"\n{'='*100}")
  70. print(f"HOW解构V9测试 - 共 {total} 个测试用例")
  71. print(f"{'='*100}")
  72. for idx, (account, file_path) in enumerate(all_files, 1):
  73. print(f"\n账号: {account}")
  74. await run_test_case(file_path, idx, total)
  75. # 添加延迟避免API限流
  76. if idx < total:
  77. print(f"\n⏸ 等待2秒后继续下一个测试用例...")
  78. await asyncio.sleep(2)
  79. print("\n" + "="*100)
  80. print(f"✅ 所有 {total} 个测试用例完成!")
  81. print("="*100)
  82. if __name__ == "__main__":
  83. asyncio.run(run_all_tests())