"""712-3 지킴 — 표 기준 → 기준배 · 기준단위 읽을 때 파생 · 배 대조 · 정본 안 씀(`master_basis`).""" from __future__ import annotations import json import sys from decimal import Decimal from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "resources/master_data/scripts")) sys.path.insert(0, str(ROOT)) import check_master as cm # noqa: E402 import master_basis as mbs # noqa: E402 def _p(text): got = mbs.parse(text) return None if got is None else (got["배"], got["단위"]) def test_parse_forms(): assert _p("10㎡당") == (Decimal(10), "㎡") assert _p("인/100본당") == (Decimal(100), "본") assert _p("ton 당") == _p("톤당") == _p("1t") == (Decimal(1), "ton") assert _p("1,000본당") == (Decimal(1000), "본") assert _p("1필지당 1,500㎡") == (Decimal(1), "필지") assert _p("일당 — 편성 1조 기준") == (Decimal(1), "일") assert _p("세면기 개당") == (Decimal(1), "개") assert _p("바닥면적㎡당") == (Decimal(1), "㎡") for text in ( "인력품", "정의", "할증", "참조", "Joint당", "단위: 인", "구하는점 5점, 주어진점 3점", ): assert _p(text) is None, text def test_fill_ratio_and_no_write(): files = cm.load() before = json.dumps(files, default=str, ensure_ascii=False) called = [ mbs.basis(t) for d in files.values() for t in d.get("표") or [] if (t.get("용도") or {}).get("로직키") ] unit = sum(1 for b in called if b["갈래"] == "단위") from_body = sum(1 for b in called if str(b["기준근거"] or "").startswith("원문")) assert unit / len(called) >= 0.78 # 로직이 부르는 표 2,023 중 1,601(79 %) assert from_body >= 280 # 빈 기준 579 중 원문 머리로 채움 285 assert json.dumps(files, default=str, ensure_ascii=False) == before # 읽기만 def test_times_mismatch_list(): """배 어긋남 = 시스템 관리자 원문 확인 거리 — 늘거나 줄면 PLAN 712-3 목록도 고침.""" found = {line.split(" · ")[0] for line in mbs.check_times(cm.load())} known = {"GC000482", "GC000483", "GC000484", "GC000485", "GF000081"} assert found == known | {"GC000522", "GC000524"} def test_edition(): assert mbs.edition("2026-01-01") == mbs.edition("2026") == "2026" assert mbs.edition(None) == "" def test_router_basis_outside_table(): from M01_MasterData import M01_MasterData_Router as router got = router.get_table("소요량_산림품셈_13장_구조물.json", "QF000443") assert got["기준파생"]["기준배"] == 10 and got["기준파생"]["기준단위"] == "㎡" assert "기준배" not in got["table"] and "기준파생" not in got["table"] listed = router.get_tables(file="소요량_산림품셈_13장_구조물.json", q="QF000443") assert listed["tables"][0]["기준파생"]["기준배"] == 10