Files
ALL-teach_sys/frontend_化工/verify_positions_update.py

88 lines
3.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import re
def verify_positions_update():
"""验证所有项目的岗位列表是否已正确更新"""
# 读取化工项目案例数据
with open('网页未导入数据/化工产业/化工项目案例.json', 'r', encoding='utf-8') as f:
source_data = json.load(f)
# 读取更新后的mock文件
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
mock_content = f.read()
print("=" * 80)
print("岗位列表更新验证报告")
print("=" * 80)
all_correct = True
total_positions_expected = 0
total_positions_found = 0
for i, project in enumerate(source_data, 1):
project_name = project.get('案例名称', '')
positions_str = project.get('适用岗位', '')
# 期望的岗位列表
if positions_str:
expected_positions = [p.strip() for p in positions_str.replace('', ',').split(',') if p.strip()]
else:
expected_positions = []
total_positions_expected += len(expected_positions)
print(f"\n项目 {i}: {project_name}")
print(f" 期望岗位数: {len(expected_positions)}")
# 在mock文件中查找该项目的岗位
# 查找项目ID后的positions数组
# 需要更精确的模式因为positions可能跨多行
pattern = rf'"id":\s*{i}[^{{]*?"positions":\s*\[((?:[^[\]]|\[[^]]*\])*?)\]'
match = re.search(pattern, mock_content, re.DOTALL)
if match:
positions_block = match.group(1)
# 提取所有岗位名称
position_matches = re.findall(r'"position":\s*"([^"]+)"', positions_block)
total_positions_found += len(position_matches)
if len(position_matches) == len(expected_positions):
# 检查每个岗位是否匹配
missing = []
for exp_pos in expected_positions:
if exp_pos not in position_matches:
missing.append(exp_pos)
if missing:
print(f" ❌ 岗位不匹配,缺少: {', '.join(missing)}")
all_correct = False
else:
print(f" ✅ 所有 {len(expected_positions)} 个岗位已正确更新")
else:
print(f" ❌ 岗位数量不匹配: 实际 {len(position_matches)},期望 {len(expected_positions)}")
print(f" 期望: {', '.join(expected_positions)}")
print(f" 实际: {', '.join(position_matches)}")
all_correct = False
else:
print(f" ❌ 未找到项目的positions数组")
all_correct = False
print("\n" + "=" * 80)
print("汇总统计")
print("=" * 80)
print(f"总期望岗位数: {total_positions_expected}")
print(f"总实际岗位数: {total_positions_found}")
if all_correct and total_positions_expected == total_positions_found:
print("\n✅ 所有项目的岗位列表已完全正确更新!")
else:
print("\n❌ 存在更新问题,请检查上述错误信息")
return all_correct
if __name__ == "__main__":
verify_positions_update()