"""B08 → B09 내역 받는 문 — 이름이 아니라 코드로 잇기 (2026-09-13, PLAN 6장 첫 일감 ①). 겨누는 것 ① 운반 줄 단가는 **그 줄로 선 내역 줄**에서 — 이름이 같은 줄(도자운반 토사·리핑암)이 둘이어도 첫 줄 단가가 둘째에 안 붙음(종전 `row.name == item.name` 실결함) ② 총 절취량은 **코드**(9-3·9-4·9-5)로 셈 — 줄 이름에 「깎기」가 없어도 검산이 돎 """ from __future__ import annotations from decimal import Decimal from functools import lru_cache import pytest import B09_Estimation.B09_Estimation_BillOfQuantities as bill_module from B09_Estimation.B09_Estimation_BillOfQuantities import build_bill from B09_Estimation.B09_Estimation_UnitPrice import build_unit_prices @lru_cache(maxsize=1) def _build(): return build_unit_prices() def _row(code: str, name: str, quantity: float, **extra) -> dict: return {"work_item_code": code, "name": name, "unit": "㎥", "quantity": quantity, **extra} def test_운반_줄_단가는_이름이_아니라_그_줄에서_읽는다(monkeypatch: pytest.MonkeyPatch) -> None: seen: list[list[dict]] = [] monkeypatch.setattr( bill_module, "check_free_haul_not_priced", lambda haul_rows: seen.append(haul_rows) ) payload = { "work_items": [ _row("FP-10-11", "dozer 운반", 10, haul_equipment="dozer", variant_value="토사"), # 같은 이름 · 표에 없는 갈래라 단가가 안 섬. _row("FP-10-11", "dozer 운반", 4, haul_equipment="dozer", variant_value="없는갈래"), ], "materials": [], } bill = build_bill(payload, build=_build()) priced = [r for r in bill.rows if not r.is_group] assert priced[0].unit_price_krw and priced[0].unit_price_krw > 0 assert priced[1].unit_price_krw is None prices = [row["unit_price_krw"] for row in seen[0]] assert prices == [priced[0].unit_price_krw, Decimal(0)] # 종전엔 둘 다 첫 줄 단가 def test_총_절취량은_코드로_센다(monkeypatch: pytest.MonkeyPatch) -> None: calls: list[dict] = [] monkeypatch.setattr( bill_module, "check_haul_volume_within_cut", lambda **kwargs: calls.append(kwargs) ) payload = { "work_items": [ # 이름에 「깎기」가 없음(마스터 표기 「토사깍기」) — 코드로만 절취임을 앎. _row("FP-09-03-02", "토사깍기", 10), _row("FP-09-12-01", "측구터파기", 3), # 절취 셈에 안 듦(종전과 같음) _row("FP-10-11", "dozer 운반", 5, haul_equipment="dozer", variant_value="토사"), ], "materials": [], } build_bill(payload, build=_build()) assert calls and calls[0]["total_cut_volume_m3"] == Decimal(10) assert calls[0]["haul_volume_total_m3"] == Decimal(5) def test_느슨한_갈래_맞춤과_못_맞춘_수량_자리는_로그로_드러난다( caplog: pytest.LogCaptureFixture, ) -> None: """명세 14장 정정(브레인 판정 (나)) — 조용히 다른 갈래에 붙는 자리를 로그로.""" import B09_Estimation.B09_Estimation_QuantityDigits as digits_module import B09_Estimation.B09_Estimation_UnitPrice as unit_price_module unit_price_module._LOOSE_LOGGED.clear() digits_module._UNMATCHED_LOGGED.clear() caplog.set_level("INFO") build = _build() # 글자 그대로 맞으면 로그 없음. assert unit_price_module.find_variant_code("FP-13-04-05", "55cm이하", build) assert "느슨한 맞춤" not in caplog.text # 한 값 45 → 구간 「55cm이하」 — 느슨한 맞춤이라 로그. assert unit_price_module.find_variant_code("FP-13-04-05", "45", build).endswith("#55cm이하") assert "느슨한 맞춤(구간): FP-13-04-05 「45」" in caplog.text # 수량 자리 — 종목 이름을 맞추면 조용하고, 못 맞추면 단위 자리로 가며 로그. assert digits_module.digits_for("돌쌓기", "㎡") == 1 assert "종목 이름을 못 맞춤" not in caplog.text assert digits_module.digits_for("사토 운반", "㎥") == 2 assert "종목 이름을 못 맞춤: 「사토 운반」 ㎥ → 단위만으로 2자리" in caplog.text