test_batch_process_business_card_images.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 测试修改后的batch_process_business_card_images函数
  5. 验证在图片解析成功后是否正确调用get_brand_group_by_hotel获取品牌和集团信息
  6. """
  7. import sys
  8. import os
  9. import logging
  10. # 添加项目根目录到Python路径
  11. sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
  12. def test_batch_process_business_card_images():
  13. """测试修改后的batch_process_business_card_images函数"""
  14. try:
  15. print("开始测试修改后的 batch_process_business_card_images 函数...")
  16. print("验证在图片解析成功后是否正确调用get_brand_group_by_hotel")
  17. print("-" * 70)
  18. # 导入函数
  19. from app.core.data_parse.parse_card import batch_process_business_card_images
  20. print("✅ 成功导入 batch_process_business_card_images 函数")
  21. # 检查函数是否包含必要的导入
  22. import inspect
  23. function_source = inspect.getsource(batch_process_business_card_images)
  24. # 检查是否导入了get_brand_group_by_hotel
  25. if "from app.core.data_parse.parse_system import get_brand_group_by_hotel" in function_source:
  26. print("✅ 函数已正确导入 get_brand_group_by_hotel")
  27. else:
  28. print("❌ 函数未导入 get_brand_group_by_hotel")
  29. return False
  30. # 检查是否调用了get_brand_group_by_hotel
  31. if "get_brand_group_by_hotel(" in function_source:
  32. print("✅ 函数已正确调用 get_brand_group_by_hotel")
  33. else:
  34. print("❌ 函数未调用 get_brand_group_by_hotel")
  35. return False
  36. # 检查是否正确赋值品牌和集团信息
  37. brand_assignments = [
  38. "talent_data['brand_zh']",
  39. "talent_data['brand_en']",
  40. "talent_data['affiliation_zh']",
  41. "talent_data['affiliation_en']"
  42. ]
  43. for assignment in brand_assignments:
  44. if assignment in function_source:
  45. print(f"✅ 函数已正确赋值 {assignment}")
  46. else:
  47. print(f"❌ 函数未赋值 {assignment}")
  48. return False
  49. print("\n✅ 所有检查项目都通过!")
  50. print("\n修改总结:")
  51. print("1. 在图片解析成功后,调用get_brand_group_by_hotel获取品牌和集团信息")
  52. print("2. 将brand_name_zh赋值给talent_data['brand_zh']")
  53. print("3. 将brand_name_en赋值给talent_data['brand_en']")
  54. print("4. 将group_name_zh赋值给talent_data['affiliation_zh']")
  55. print("5. 将group_name_en赋值给talent_data['affiliation_en']")
  56. print("6. 包含完善的错误处理和日志记录")
  57. print("7. 在调用record_parsed_talent之前完成所有数据准备")
  58. return True
  59. except Exception as e:
  60. print(f"\n❌ 测试失败: {str(e)}")
  61. import traceback
  62. traceback.print_exc()
  63. return False
  64. if __name__ == "__main__":
  65. # 配置日志
  66. logging.basicConfig(
  67. level=logging.INFO,
  68. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
  69. )
  70. # 运行测试
  71. success = test_batch_process_business_card_images()
  72. if success:
  73. print("\n🎉 测试完成!函数修改成功!")
  74. else:
  75. print("\n�� 测试失败!需要检查函数修改!")