123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #!/usr/bin/env python3
- """
- 测试年龄格式化和日期格式化功能
- """
- import os
- import sys
- import logging
- from pathlib import Path
- # 添加项目根目录到Python路径
- project_root = Path(__file__).parent
- sys.path.insert(0, str(project_root))
- # 配置日志
- logging.basicConfig(
- level=logging.INFO,
- format='%(asctime)s - %(levelname)s - %(message)s'
- )
- def test_formatting_functions():
- """测试格式化函数"""
- try:
- # 导入函数
- from app.core.data_parse.parse_resume import format_date_to_yyyy_mm_dd
-
- print("开始测试日期格式化功能...")
-
- # 测试各种日期格式
- test_dates = [
- "2023.11",
- "2023-11",
- "2023年11月",
- "2023/11",
- "202311",
- "2023.11.01",
- "2023-11-01",
- "2023年11月1日",
- "2023/11/01",
- "2009.08",
- "2013.11",
- "2017.04",
- "2019.12",
- "无效日期",
- ""
- ]
-
- print("\n=== 日期格式化测试 ===")
- for test_date in test_dates:
- formatted = format_date_to_yyyy_mm_dd(test_date)
- print(f"原始: '{test_date}' -> 格式化: '{formatted}'")
-
- return True
-
- except Exception as e:
- print(f"测试失败: {str(e)}")
- import traceback
- traceback.print_exc()
- return False
- def test_age_formatting():
- """测试年龄格式化功能"""
- try:
- print("\n开始测试年龄格式化功能...")
-
- # 测试年龄字段映射
- test_ages = [
- "37岁",
- "25岁",
- "42岁",
- "30",
- "年龄不详",
- ""
- ]
-
- print("\n=== 年龄格式化测试 ===")
- for test_age in test_ages:
- import re
- age_match = re.search(r'(\d+)', str(test_age))
- if age_match:
- formatted_age = age_match.group(1)
- print(f"原始: '{test_age}' -> 格式化: '{formatted_age}'")
- else:
- print(f"原始: '{test_age}' -> 格式化: ''")
-
- return True
-
- except Exception as e:
- print(f"测试失败: {str(e)}")
- import traceback
- traceback.print_exc()
- return False
- def test_full_resume_parsing():
- """测试完整的简历解析功能"""
- try:
- # 导入函数
- from app.core.data_parse.parse_resume import parse_resume_with_qwen
-
- # 测试文件路径
- test_file = "方全.pdf"
-
- # 检查文件是否存在
- if not os.path.exists(test_file):
- print(f"错误: 测试文件 {test_file} 不存在")
- return False
-
- print(f"\n开始测试完整简历解析功能...")
- print(f"测试文件: {test_file}")
-
- # 调用函数
- result = parse_resume_with_qwen(test_file)
-
- # 输出格式化后的结果
- print("\n=== 格式化后的解析结果 ===")
- print(f"姓名(中文): {result.get('name_zh', 'N/A')}")
- print(f"年龄: {result.get('age', 'N/A')}")
-
- # 输出职业轨迹
- career_path = result.get('career_path', [])
- if career_path:
- print(f"\n职业轨迹 (共{len(career_path)}条):")
- for i, career in enumerate(career_path, 1):
- print(f" {i}. 日期: {career.get('date', 'N/A')}")
- print(f" 公司: {career.get('hotel_zh', 'N/A')}")
- print(f" 职位: {career.get('title_zh', 'N/A')}")
- else:
- print("\n职业轨迹: 无")
-
- print("\n=== 完整测试完成 ===")
- return True
-
- except Exception as e:
- print(f"测试失败: {str(e)}")
- import traceback
- traceback.print_exc()
- return False
- if __name__ == "__main__":
- print("=" * 50)
- print("测试格式化功能")
- print("=" * 50)
-
- # 测试日期格式化
- success1 = test_formatting_functions()
-
- # 测试年龄格式化
- success2 = test_age_formatting()
-
- # 测试完整简历解析
- success3 = test_full_resume_parsing()
-
- print("\n" + "=" * 50)
- print("测试总结:")
- print(f"日期格式化测试: {'✓ 成功' if success1 else '✗ 失败'}")
- print(f"年龄格式化测试: {'✓ 成功' if success2 else '✗ 失败'}")
- print(f"完整简历解析测试: {'✓ 成功' if success3 else '✗ 失败'}")
- print("=" * 50)
|