test_real_dataset.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from pathlib import Path
  2. import pytest
  3. from standards_service.service.matcher import StandardMatcher
  4. REAL_CSV = Path(__file__).resolve().parents[2] / "归集617清洗.csv"
  5. @pytest.fixture(scope="module")
  6. def real_matcher():
  7. if not REAL_CSV.exists():
  8. pytest.skip("真实规范清单不存在")
  9. return StandardMatcher.from_csv(REAL_CSV)
  10. def test_real_exact_code(real_matcher):
  11. candidates = real_matcher.search("GB 50330-2013 建筑边坡工程技术规范")
  12. assert candidates[0]["code"] == "GB 50330-2013"
  13. assert candidates[0]["match_score"] == 1.0
  14. def test_real_code_without_year_returns_known_versions(real_matcher):
  15. codes = [item["code"] for item in real_matcher.search("GB 50330")]
  16. assert codes[:2] == ["GB 50330-2013", "GB 50330-2002"]
  17. def test_real_standard_type_variant(real_matcher):
  18. candidates = real_matcher.search("GB/T 6441-1986")
  19. assert candidates[0]["code"] == "GB 6441-1986"
  20. assert candidates[0]["match_score"] == 0.93
  21. def test_real_single_character_code_typo_with_title(real_matcher):
  22. candidates = real_matcher.search("TG/T 5440-2018 公路隧道加固技术规范")
  23. assert candidates[0]["code"] == "JTG/T 5440-2018"
  24. def test_real_wrong_year_still_returns_related_title(real_matcher):
  25. candidates = real_matcher.search(
  26. "公路隧道设计规范(第二册)交通工程与附属设施(JTG D70/2-2014)"
  27. )
  28. assert candidates[0]["code"] == "JTG D70-2004"
  29. assert candidates[0]["match_score"] < 0.8
  30. def test_real_year_conflict_exact_title_is_returned(real_matcher):
  31. candidates = real_matcher.search("钢筋焊接及验收规程JGJ 18-2022")
  32. assert candidates[0]["code"] == "JGJ 18-2012"
  33. assert candidates[0]["match_score"] == 0.91