conftest.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import csv
  2. from pathlib import Path
  3. import pytest
  4. HEADERS = [
  5. "query_keyword",
  6. "csres_ok",
  7. "csres_crawl_status",
  8. "csres_normalized_code",
  9. "csres_code",
  10. "csres_title",
  11. "csres_status",
  12. "csres_relation_text",
  13. "csres_implement_date",
  14. "csres_source_url",
  15. "csres_log_file",
  16. "checked_at",
  17. "error_message",
  18. "manual_review_note",
  19. ]
  20. def row(code, title, status="现行", relation="", date="2020-01-01", normalized=None):
  21. return {
  22. "query_keyword": code,
  23. "csres_ok": "TRUE",
  24. "csres_crawl_status": "success",
  25. "csres_normalized_code": normalized or code,
  26. "csres_code": code,
  27. "csres_title": title,
  28. "csres_status": status,
  29. "csres_relation_text": relation,
  30. "csres_implement_date": date,
  31. "csres_source_url": "",
  32. "csres_log_file": "",
  33. "checked_at": "2026-06-22T10:00:00",
  34. "error_message": "",
  35. "manual_review_note": "",
  36. }
  37. @pytest.fixture
  38. def standard_rows():
  39. return [
  40. row("GB 50330-2002", "建筑边坡工程技术规范", "已作废", "被 GB 50330-2013 代替", "2002-08-01"),
  41. row("GB 50330-2013", "建筑边坡工程技术规范", "现行", "替代 GB 50330-2002", "2014-06-01"),
  42. row("GB 50330-2018", "建筑边坡工程技术规范", "已作废", "被 GB 50330-2023 代替", "2018-06-01"),
  43. row("GB 50330-2023", "建筑边坡工程技术规范", "现行", "替代 GB 50330-2018", "2023-06-01"),
  44. row("CJJ 69-1995", "城市人行天桥与人行地道技术规范"),
  45. row("GB 6441-1986", "企业职工伤亡事故分类"),
  46. row("GB/T 13544-2011", "烧结多孔砖和多孔砌块"),
  47. row("JTG/T 5440-2018", "公路隧道加固技术规范"),
  48. row("JTG D70-2004", "公路隧道设计规范", "已作废"),
  49. row("JGJ 18-2012", "钢筋焊接及验收规程"),
  50. row("NEW 100-2020", "新标准", relation="替代 OLD 100-2000"),
  51. row("GB 50010-2010", "混凝土结构设计规范"),
  52. ]
  53. def write_csv(path: Path, rows, encoding="utf-8"):
  54. with path.open("w", encoding=encoding, newline="") as file:
  55. writer = csv.DictWriter(file, fieldnames=HEADERS)
  56. writer.writeheader()
  57. writer.writerows(rows)
  58. return path
  59. @pytest.fixture
  60. def standards_csv(tmp_path, standard_rows):
  61. return write_csv(tmp_path / "standards.csv", standard_rows)