#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 测试修改后的batch_process_business_card_images函数 验证在图片解析成功后是否正确调用get_brand_group_by_hotel获取品牌和集团信息 """ import sys import os import logging # 添加项目根目录到Python路径 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) def test_batch_process_business_card_images(): """测试修改后的batch_process_business_card_images函数""" try: print("开始测试修改后的 batch_process_business_card_images 函数...") print("验证在图片解析成功后是否正确调用get_brand_group_by_hotel") print("-" * 70) # 导入函数 from app.core.data_parse.parse_card import batch_process_business_card_images print("✅ 成功导入 batch_process_business_card_images 函数") # 检查函数是否包含必要的导入 import inspect function_source = inspect.getsource(batch_process_business_card_images) # 检查是否导入了get_brand_group_by_hotel if "from app.core.data_parse.parse_system import get_brand_group_by_hotel" in function_source: print("✅ 函数已正确导入 get_brand_group_by_hotel") else: print("❌ 函数未导入 get_brand_group_by_hotel") return False # 检查是否调用了get_brand_group_by_hotel if "get_brand_group_by_hotel(" in function_source: print("✅ 函数已正确调用 get_brand_group_by_hotel") else: print("❌ 函数未调用 get_brand_group_by_hotel") return False # 检查是否正确赋值品牌和集团信息 brand_assignments = [ "talent_data['brand_zh']", "talent_data['brand_en']", "talent_data['affiliation_zh']", "talent_data['affiliation_en']" ] for assignment in brand_assignments: if assignment in function_source: print(f"✅ 函数已正确赋值 {assignment}") else: print(f"❌ 函数未赋值 {assignment}") return False print("\n✅ 所有检查项目都通过!") print("\n修改总结:") print("1. 在图片解析成功后,调用get_brand_group_by_hotel获取品牌和集团信息") print("2. 将brand_name_zh赋值给talent_data['brand_zh']") print("3. 将brand_name_en赋值给talent_data['brand_en']") print("4. 将group_name_zh赋值给talent_data['affiliation_zh']") print("5. 将group_name_en赋值给talent_data['affiliation_en']") print("6. 包含完善的错误处理和日志记录") print("7. 在调用record_parsed_talent之前完成所有数据准备") return True except Exception as e: print(f"\n❌ 测试失败: {str(e)}") import traceback traceback.print_exc() return False if __name__ == "__main__": # 配置日志 logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) # 运行测试 success = test_batch_process_business_card_images() if success: print("\n🎉 测试完成!函数修改成功!") else: print("\n�� 测试失败!需要检查函数修改!")