"""B09 [저장] 속도 — 같은 결과 범위 안 다시 셈 줄임 지킴. - 산근 두 번 셈(183-1) = 1차 풀이 그대로(841-1 산근 단가 = M02 엔진 · 바탕 표 안 읽음 → 늘 같음) - M01 `steady()` 범위 = 파일 자국 한 번 · `stale` 뒤 다시 셈 · 범위 밖은 늘 셈 - B08 `once()` 범위 = 채집석 공제가 자재 집계표 답을 다시 씀(셈 한 번) """ from __future__ import annotations import asyncio import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT)) from B08_Quantity import B08_Quantity_Router_Material as material # noqa: E402 from B09_Estimation import B09_Estimation_Sangeun as sg # noqa: E402 from M01_MasterData import M01_MasterData_Store_Cache as cache # noqa: E402 def test_산근_두_번_셈_앞_풀이_그대로() -> None: memo = {"sg": {"sg": [{"key": "SG:x"}], "sg_list": [], "sg_gaps": [], "sg_notes": [], "sg_hand": {}}} # fmt: skip got = sg.collect([("s1", ROOT / "없는 사본")], None, memo) assert got == memo["sg"] and got is not memo["sg"] # 사본(깊은 복사) def test_M01_범위_안_자국_한_번(monkeypatch) -> None: calls = [] monkeypatch.setattr(cache, "_stamps", lambda folder: calls.append(folder) or {}) folder = Path("x") cache._now(folder) cache._now(folder) assert len(calls) == 2 # 범위 밖 = 늘 셈 with cache.steady(): cache._now(folder) cache._now(folder) assert len(calls) == 3 cache.stale([]) # 스스로 고친 자리 = 다시 셈 cache._now(folder) assert len(calls) == 4 cache._now(folder) assert len(calls) == 5 def test_B08_범위_안_자재_집계표_한_번(monkeypatch, tmp_path) -> None: calls = [] rows = [{"key": material.DEDUCT_KEY, "amount": 12.5}] async def sheets(_pid, _root, _over): calls.append(1) return {"sheets": {"material": {"rows": rows}}} async def root(_pid): return tmp_path monkeypatch.setattr(material, "_sheets", sheets) monkeypatch.setattr(material, "_project_root", root) monkeypatch.setattr(material, "quantity_settings", lambda _root: {}) async def run() -> list: out = [await material.picked_deduction("p", tmp_path)] with material.once(): await material.material_sheets("p") out.append(await material.picked_deduction("p", tmp_path)) out.append(await material.picked_deduction("p", tmp_path)) return out assert asyncio.run(run()) == [12.5, 12.5, 12.5] assert len(calls) == 3 # 범위 안 공제 = 셈 없음