import csv from pathlib import Path import pytest HEADERS = [ "query_keyword", "csres_ok", "csres_crawl_status", "csres_normalized_code", "csres_code", "csres_title", "csres_status", "csres_relation_text", "csres_implement_date", "csres_source_url", "csres_log_file", "checked_at", "error_message", "manual_review_note", ] def row(code, title, status="现行", relation="", date="2020-01-01", normalized=None): return { "query_keyword": code, "csres_ok": "TRUE", "csres_crawl_status": "success", "csres_normalized_code": normalized or code, "csres_code": code, "csres_title": title, "csres_status": status, "csres_relation_text": relation, "csres_implement_date": date, "csres_source_url": "", "csres_log_file": "", "checked_at": "2026-06-22T10:00:00", "error_message": "", "manual_review_note": "", } @pytest.fixture def standard_rows(): return [ row("GB 50330-2002", "建筑边坡工程技术规范", "已作废", "被 GB 50330-2013 代替", "2002-08-01"), row("GB 50330-2013", "建筑边坡工程技术规范", "现行", "替代 GB 50330-2002", "2014-06-01"), row("GB 50330-2018", "建筑边坡工程技术规范", "已作废", "被 GB 50330-2023 代替", "2018-06-01"), row("GB 50330-2023", "建筑边坡工程技术规范", "现行", "替代 GB 50330-2018", "2023-06-01"), row("CJJ 69-1995", "城市人行天桥与人行地道技术规范"), row("GB 6441-1986", "企业职工伤亡事故分类"), row("GB/T 13544-2011", "烧结多孔砖和多孔砌块"), row("JTG/T 5440-2018", "公路隧道加固技术规范"), row("JTG D70-2004", "公路隧道设计规范", "已作废"), row("JGJ 18-2012", "钢筋焊接及验收规程"), row("NEW 100-2020", "新标准", relation="替代 OLD 100-2000"), row("GB 50010-2010", "混凝土结构设计规范"), ] def write_csv(path: Path, rows, encoding="utf-8"): with path.open("w", encoding=encoding, newline="") as file: writer = csv.DictWriter(file, fieldnames=HEADERS) writer.writeheader() writer.writerows(rows) return path @pytest.fixture def standards_csv(tmp_path, standard_rows): return write_csv(tmp_path / "standards.csv", standard_rows)