"""855-A 지킴 ④ — 막힘 판정 옛(`master_formula.check_logic` · M01 로직 목록 · `/logic`) = 새(수식 문서 표지 `master_doc.check`) 전수 · 막힘 기준 = 표지만(기본 입력으로 셈이 안 되는 것은 막힘 아님 · 판정 855-0). 걸음 2-B3(막힘 검사를 문서 기준으로) 앞뒤로 같아야 함 · 옛 검사를 지우는 걸음에서 옛 쪽만 뗌.""" from __future__ import annotations import importlib import helper_855_engine as h md = importlib.import_module("master_doc") def test_막힘_옛_새_같음(): rows, whole, docs, _ = h.world() old = {str(r["키"]) for r in rows if h.mf.check_logic(whole, r)[0]} new = {str(r["키"]) for r in rows if str(r["키"]) not in docs or md.check(docs[str(r["키"])])} assert old == new, {"옛만 막힘": sorted(old - new)[:20], "새만 막힘": sorted(new - old)[:20]} def test_틀린_식은_옛_새_모두_막힘(): """자가 살아 있는지 — 같은 로직의 식을 틀리게 하면 두 판정 모두 막힘(사본만 · 자료 안 고침).""" import copy rows, whole, docs, _ = h.world() row = next(r for r in rows if r.get("호표") and str(r["키"]) in docs) bad_row = copy.deepcopy(row) bad_row["호표"][0]["수량"] = "없는변수 * 2" bad_doc = copy.deepcopy(docs[str(row["키"])]) bad_doc["금액"][0]["수량"] = "없는기호 × 2" assert h.mf.check_logic(whole, bad_row)[0] assert md.check(bad_doc) def test_화면_답이_문서_막힘_길을_씀(monkeypatch): """2-B3 뒤 — M01 `/logic` 막힘 · 목록 막힘 · 일위대가 조합 막힘이 수식 문서 기준(`master_doc_block`). 문서 하나를 틀리게(사본) 하면 로직 줄은 그대로인데 화면 답이 막힘으로 바뀜 · 문서가 빠지면 조합도 막힘.""" import copy from M01_MasterData import M01_MasterData_Doc as doc_store from M01_MasterData import M01_MasterData_Store as store from M01_MasterData import M01_MasterData_Store_Combo as combo_store real = doc_store.docs() key = next(k for k, d in real.items() if d.get("금액")) assert not store.logic(key)["blocked"] and not store.blocks()[key] bad = copy.deepcopy(real[key]) bad["금액"][0]["수량"] = "없는기호 × 2" monkeypatch.setattr(doc_store, "docs", lambda: {**real, key: bad}) got = store.logic(key) assert got["blocked"] and any("없는기호" in x for x in got["reasons"]) assert store.blocks()[key] == got["reasons"] row = {"키": "UA999999", "이름": "시험", "담은로직": [{"로직": key}]} assert combo_store.problems_of(row) == [] monkeypatch.setattr(doc_store, "docs", lambda: {k: d for k, d in real.items() if k != key}) assert combo_store.problems_of(row) == [f"UA999999 시험 줄1 · 없는 요소 「{key}」"] assert store.logic(key)["reasons"] == [] # 문서 없는 줄 = 막힘 아님(지금 그대로) def test_저장_검사_부름_닫힘_순환(): """저장 검사 로직 몫(`master_doc_block.check_docs`) — 부르는 단가산출이 빠지면 막힘 · 문서 사이 순환.""" mb = importlib.import_module("master_doc_block") _, _, docs, _ = h.world() caller = next(k for k, d in docs.items() if mb.calls(d)) called = sorted(mb.calls(docs[caller]))[0] assert not mb.check_docs(docs, {caller}) gone = {k: d for k, d in docs.items() if k != called} assert any(f"「{called}」 없음" in x for x in mb.check_docs(gone, {caller})) a = {"꼴": "수식문서", "키": "GX900001", "변수": [{"열쇠": "b", "기호": "b", "연결": {"갈래": "단가산출", "키": "GX900002"}}]} # fmt: skip b = {**a, "키": "GX900002", "변수": [{"열쇠": "a", "기호": "a", "연결": {"갈래": "단가산출", "키": "GX900001"}}]} # fmt: skip assert any("돌고 도는 참조" in x for x in mb.check_docs({"GX900001": a, "GX900002": b}, set())) def test_요소_닫힘_쓰이는_요소가_없으면_막힘(): """요소 닫힘 — 문서가 부르는 요소 · 표가 마스터에 없으면 막힘(쓰이는 요소를 지우면 저장이 막는 지금 동작 지킴) · 단가산출에 넘기는 입력 이름이 부르는 문서에 없으면 막힘.""" import copy mb = importlib.import_module("master_doc_block") _, whole, docs, _ = h.world() key, doc = next( (k, d) for k, d in docs.items() if any( (v.get("연결") or {}).get("갈래") == "요소" and str((v.get("연결") or {}).get("키") or "").startswith("LB0") for v in d.get("변수") or [] ) ) assert not mb.reasons(key, doc, docs, whole) gone = copy.deepcopy(doc) link = next( v["연결"] for v in gone["변수"] if str((v.get("연결") or {}).get("키") or "").startswith("LB0") ) link["키"] = "LB999999" assert any("LB999999" in x for x in mb.reasons(key, gone, docs, whole)) caller = next(k for k, d in docs.items() if mb.calls(d)) bad = copy.deepcopy(docs[caller]) call = next(v["연결"] for v in bad["변수"] if (v.get("연결") or {}).get("갈래") == "단가산출") call["입력"] = {**(call.get("입력") or {}), "없는입력": "1"} assert any("없는입력" in x for x in mb.reasons(caller, bad, docs, whole))