from pathlib import Path import pytest from standards_service.service.matcher import StandardMatcher REAL_CSV = Path(__file__).resolve().parents[2] / "归集617清洗.csv" @pytest.fixture(scope="module") def real_matcher(): if not REAL_CSV.exists(): pytest.skip("真实规范清单不存在") return StandardMatcher.from_csv(REAL_CSV) def test_real_exact_code(real_matcher): candidates = real_matcher.search("GB 50330-2013 建筑边坡工程技术规范") assert candidates[0]["code"] == "GB 50330-2013" assert candidates[0]["match_score"] == 1.0 def test_real_code_without_year_returns_known_versions(real_matcher): codes = [item["code"] for item in real_matcher.search("GB 50330")] assert codes[:2] == ["GB 50330-2013", "GB 50330-2002"] def test_real_standard_type_variant(real_matcher): candidates = real_matcher.search("GB/T 6441-1986") assert candidates[0]["code"] == "GB 6441-1986" assert candidates[0]["match_score"] == 0.93 def test_real_single_character_code_typo_with_title(real_matcher): candidates = real_matcher.search("TG/T 5440-2018 公路隧道加固技术规范") assert candidates[0]["code"] == "JTG/T 5440-2018" def test_real_wrong_year_still_returns_related_title(real_matcher): candidates = real_matcher.search( "公路隧道设计规范(第二册)交通工程与附属设施(JTG D70/2-2014)" ) assert candidates[0]["code"] == "JTG D70-2004" assert candidates[0]["match_score"] < 0.8 def test_real_year_conflict_exact_title_is_returned(real_matcher): candidates = real_matcher.search("钢筋焊接及验收规程JGJ 18-2022") assert candidates[0]["code"] == "JGJ 18-2012" assert candidates[0]["match_score"] == 0.91