Files
Aislo/resources/tester/test_855_sk_layers.py
T
eomsangdonandClaude Opus 5.5 dd8759edc5 refactor(855-E 2-E4 ㉯-4 ⑥): 옛 계산 엔진 몸 지움 — master_formula 무리 아홉 · 계산기 하나
- git rm(부르는 곳 0 다시 셈 — import · import_module 글 · getattr 별칭 cm.mf · store.mau · mtx 포함): master_formula · master_formula_check · master_formula_sum · master_text · master_text_item · master_sheet_line · master_gate · master_auto · master_copy(−2,625 줄)
- master_cut = down · row · sums 만(일위대가 반영 끝수 · TS 짝) — engine · settle · plain · _line · _sub · kept(손님 0) 지움 · 바탕 = master_base
- master_bundle = BUNDLES · BY_ITEM · BY_KIND · is_machine(M01 목록 묶음) — called · bundle · tag 지움 · master_combo = 조합 칸만(run 지움)
- check_master · check_master_body · compare_estx: import master_formula → master_base(바탕 이름만) · compare_estx 기계 · 일위대가 대조 = 수식 문서 셈(옛 mf.run · 로직 줄 고르기 덧붙임 걷음 · 일위대가 28 · 기계 207 건 그대로 나옴)
- M01 Store: 다시 내보냄 mau · mtx 지움(부르는 곳 0) · cm.mf = master_base
- 죽은 주석: master_material · master_pick · master_base · Item_Prices · San_Emit · check_master
- test_855_sk_layers: 옛 엔진 안 돎 = 엔진 모듈 없음 확인
- 검증: 관련 146 파일 1,135 통과 · test_855_golden 전수 지문 같음 · 모든 제품 · scripts 모듈 읽기 깨짐 0 · typecheck 0 · 8008 health 200 · 로그 오류 0 · 서버 길 469 → 469

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 16:02:20 +09:00

147 lines
5.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ruff: noqa: F811 — 임시 층 fixture(world)를 test_m02_labor_ref 에서 받아 씀
"""855 지킴 ③ — 단가산출(SK) 셈 답 = 수식 사본 문서 셈 한 길(2-C1) · 견본 꼴마다.
견본(임시 storage · 개인 층 · M01 은 읽기만): 바탕 로직 · 율 바탕 · 형제 SK(바탕 참조로 만듦) ·
「따로」(수식 사본을 고쳐 저장) · 가져온 식(엑셀 줄 · 저장 없음) · 옛 칸 고침(더한줄 로직 · 율 더한줄).
판정 — 셈 답 기준 = 수식 길 셈(`M02_Doc_Sk_Path` · 화면 줄 쌓기와 같은 계산기) · 줄 비목 합(원 버림 ·
합밖 줄 뺌) = 기준 · 줄 수 > 0 · 옛 칸 고침 SK = 못 셈 + 까닭 하나(옛 엔진 안 돎 · 올림 없음).
"""
from __future__ import annotations
import copy
from decimal import ROUND_DOWN, Decimal
import pytest
from M01_MasterData import M01_MasterData_Store as m01
from M02_MasterTemplete import M02_Doc_Sk as dsk
from M02_MasterTemplete import M02_Doc_Sk_Path as path
from M02_MasterTemplete import M02_Labor_Doc as labor
from M02_MasterTemplete import M02_MasterTemplete_Store as store
from M02_MasterTemplete import M02_Sangeun_Calc as calc
from M02_MasterTemplete import M02_Sangeun_Doc as sd
from resources.tester import test_793_2_sangeun_imported as imported
from resources.tester.test_778_4_rate_line import SUB, _rate
from resources.tester.test_795_1_sk_copy import PCT, _doc, _sk
from resources.tester.test_m02_labor_ref import world # noqa: F401 — 같은 임시 층
COSTS = ("노무비", "재료비", "경비")
FORM = "GC000211" # 합판거푸집
ADD = {"종류": "로직", "로직": "GF000089", "수량": 2, "입력값": {}, "이름": "sub6임시 굴착기"}
@pytest.fixture(autouse=True)
def _manual(monkeypatch):
"""자동 따라옴 끔 — 저장본 그대로 셈(층 꼴만 봄)."""
from M02_MasterTemplete import M02_Sk_AutoRenew as renew
monkeypatch.setattr(renew, "on", lambda: False)
def _run(folder, doc: dict) -> dict:
whole = m01.loaded()[1]
with store.at(folder):
return calc.run(sd.clean(doc, None, whole), whole)
def _lines_sum(got: dict) -> dict:
total = {k: Decimal(0) for k in COSTS}
for ln in got.get("줄") or []:
for k in COSTS:
v = (ln.get("비목") or {}).get(k)
total[k] += Decimal(str(v)) if v is not None and not ln.get("합밖") else 0
return {k: v.quantize(Decimal(1), ROUND_DOWN) for k, v in total.items()}
def _base(got: dict) -> dict:
return {k: Decimal(str(got["기준"][k])).quantize(Decimal(1), ROUND_DOWN) for k in COSTS}
def _one_path(got: dict, screen: dict | None = None) -> None:
"""한 길 — 문서 셈 · 줄 있음 · 줄 합 = 기준 · (있으면) 수식 길 셈과 같음."""
assert got["수식셈"]["셈됨"] is True and got["기준"] is not None
assert len(got["줄"]) > 0
assert _lines_sum(got) == _base(got)
if screen is not None:
assert {k: Decimal(str(got["기준"][k])) for k in COSTS} == {
k: Decimal(str(screen[k])) for k in COSTS
}
def _screen(folder, key: str) -> dict:
with store.at(folder):
return path.read(key)["셈"]
@pytest.mark.parametrize(
"body",
[{"바탕": {"로직": FORM}}, {"바탕": {"로직": PCT}}],
ids=["바탕", "율_바탕"],
)
def test_층_SK_한_길_줄_합_기준(world, body):
me = world["personal"]
key = _sk(me, **copy.deepcopy(body))
_one_path(_run(me, _doc(me, key)), _screen(me, key))
def test_옛_엔진_안_돎(world):
"""옛 엔진 모듈(`master_formula` 무리) 없음 · 옛 줄 셈 함수 없음 · 한 번 셈 됨(855-E 2-E4)."""
import importlib.util
me = world["personal"]
key = _sk(me, 바탕={"로직": FORM})
gone = ("master_formula", "master_formula_sum", "master_auto", "master_text", "master_equation")
assert [m for m in gone if importlib.util.find_spec(m)] == []
assert not hasattr(labor, "run_line")
_one_path(_run(me, _doc(me, key)))
@pytest.mark.parametrize(
"body",
[
{"바탕": {"로직": FORM}, "더한줄": [ADD]}, # 옛 칸 값(더한줄 로직)
{"바탕": {"로직": SUB}, "더한줄": [_rate("인력", 2)], "단위": "주"}, # 율 더한줄
],
ids=["옛칸_더한줄", "율_더한줄"],
)
def test_옛_칸_고침_SK_못_셈_까닭(world, body):
me = world["personal"]
key = _sk(me, **copy.deepcopy(body))
got = _run(me, _doc(me, key))
assert got["기준"] is None and got["줄"] == []
assert got["까닭"] == dsk.OLD_WHY
assert calc.unit(_doc(me, key), m01.loaded()[1], None, ())["까닭"] == dsk.OLD_WHY
def test_형제_SK_바탕_참조(world):
me = world["personal"]
first = _sk(me, 바탕={"로직": FORM})
second = _sk(me, 바탕={"참조": {"층": "personal", "주인": "7/42", "키": first}})
new = _run(me, _doc(me, second))
_one_path(new)
assert new["기준"] == _run(me, _doc(me, first))["기준"]
def test_가져온_식(world):
new = _run(world["personal"], imported._doc())
_one_path(new)
def test_따로_SK_줄도_문서_답(world):
"""「따로」 = 고친 수식 사본이 정본 — 줄 · 기준 모두 그 문서 셈(2-C1 전에는 줄 = 옛 엔진으로 갈렸음)."""
me = world["personal"]
key = _sk(me, 바탕={"로직": PCT})
plain = _run(me, _doc(me, key))
with store.at(me):
read = path.read(key)
twice = copy.deepcopy(read["문서"])
line = twice["금액"][0]
line["수량"] = f"({line.get('수량') or 1}) × 2"
saved = path.save(key, {"문서": twice, "판": read["판"]})
assert saved["사본"]["따로"] is True
new = _run(me, _doc(me, key))
assert new["수식셈"]["따로"] is True
_one_path(new, saved["셈"])
assert _base(new) != _base(plain) # 고친 문서 = 새 금액