zbparse/flask_app/test_case/test_正则表达式.py

114 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
# 定义清理函数
def clean_data(data):
pattern = r'^\s*(?:[(]\d+[))]|[A-Za-z]?\d+(?:\.\s*\d+)*[\s\.、.)\]+|[一二三四五六七八九十]+、|[A-Z][)\.、.]?\s*)'
return re.sub(pattern, '', data).strip()
# 定义测试用例
test_cases = [
{
"description": "阿拉伯数字加逗号",
"input": "2 、单位负责人为同一人或者存在直接控股 、管理关系的不同投标人, 不得 参加本项目同一合同项下的政府采购活动。",
"expected": "单位负责人为同一人或者存在直接控股 、管理关系的不同投标人, 不得 参加本项目同一合同项下的政府采购活动。"
},
{
"description": "阿拉伯数字加点",
"input": "3. 为本采购项目提供整体设计 、规范编制或者项目管理 、监理 、检测等服务的, 不得再参加本项目的其他招标采购活动。",
"expected": "为本采购项目提供整体设计 、规范编制或者项目管理 、监理 、检测等服务的, 不得再参加本项目的其他招标采购活动。"
},
{
"description": "阿拉伯数字加圆括号",
"input": "(4) 详细说明",
"expected": "详细说明"
},
{
"description": "全角括号",
"input": "5项目概述",
"expected": "项目概述"
},
{
"description": "字母加点",
"input": "A. 项目简介",
"expected": "项目简介"
},
{
"description": "字母加逗号",
"input": "B、详细内容",
"expected": "详细内容"
},
{
"description": "中文数字加逗号",
"input": "一、项目背景",
"expected": "项目背景"
},
{
"description": "中文数字加逗号和空格",
"input": "二 、项目目标",
"expected": "项目目标"
},
{
"description": "混合分隔符",
"input": "C) 项目计划",
"expected": "项目计划"
},
{
"description": "没有序号",
"input": "这是一个没有序号的段落。",
"expected": "这是一个没有序号的段落。"
},
{
"description": "多个分隔符",
"input": "3 、 为本采购项目提供整体设计",
"expected": "为本采购项目提供整体设计"
},
{
"description": "复杂的编号格式",
"input": "A.1.1. 详细步骤",
"expected": "详细步骤"
},
{
"description": "中英文混合的中文数字",
"input": "(六)第五部分",
"expected": "第五部分"
},
{
"description": "无空格的分隔符",
"input": "7、没有空格的情况",
"expected": "没有空格的情况"
},
{
"description": "分隔符前有空格",
"input": "8 、 有空格的情况",
"expected": "有空格的情况"
},
{
"description": "点和逗号混合的分隔符",
"input": "9. 、 混合分隔符",
"expected": "混合分隔符"
},
{
"description": "多重括号",
"input": "((10)) 多重括号",
"expected": "多重括号"
},
{
"description": "只有数字",
"input": "10 多重括号",
"expected": "多重括号"
}
]
# 执行测试
for idx, case in enumerate(test_cases, 1):
input_data = case["input"]
expected = case["expected"]
result = clean_data(input_data)
passed = result == expected
status = "通过" if passed else "失败"
print(f"测试 {idx}: {case['description']}")
print(f"原始数据: {input_data}")
print(f"预期结果: {expected}")
print(f"实际结果: {result}")
print(f"测试结果: {status}\n{'-'*50}\n")