Files
Aislo/resources/tester/test_855_sk_layers.py
T
eomsangdonandClaude Opus 5.5 327fdc5d9b test(855-A): 걸음 2 지킴 시험 다섯 — 옛 엔진 대 새 계산기 · 새 답 지문 · SK 견본 · 막힘 · 불러오기 옛 검산
- test_855_engine_parity: 로직 전수 기본 입력 L0 ~ L3 옛 대 새 · 다름 = 채택 목록(빌더 ADOPTED)과 같음 · 보이는 단가만 다름은 허용 갈래 · 옵션 전수 = S855_ALL=1
- test_855_golden + golden_855_engine.json: 새 계산기 답 지문(로직마다 기본 + 옵션 표본) · 다르면 실패 · 다시 뜨기 = --write(자료를 뜻대로 바꾼 걸음만)
- test_855_sk_layers: 임시 층 SK 견본(바탕 · 옛 칸 더한줄 · 율 더한줄 · 형제 SK · 가져온 식) 옛 = 새 · 줄 합 = 기준 · 「따로」 는 지금 사실(줄 = 옛 · 기준 = 새)을 단언 — 2-C1 에서 뒤집음
- test_855_block: 막힘 옛(check_logic) = 새(문서 표지) · 틀린 식은 둘 다 막힘
- test_812_1_xlsx_golden: 금액 표본 sweep 에 옛 검산(옛 엔진) = 새 셈 단언 하나
- 도우미 helper_855_engine(경우 · 층 가름 · 지문) · 제품 코드 고침 0
- 싱크 관문에는 안 넣음 — 기존 관문 넷이 이미 약 7 분(5 분 넘음)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:45:14 +09:00

126 lines
5.0 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-A 지킴 ③ — 단가산출(SK) 셈 답 · 견본 꼴마다 옛 엔진 길(`M02_Doc_Sk.OLD`) 대 지금 길(수식 사본 →
문서 계산기) · 지금 길 답의 줄 비목 합(원 버림) = 기준.
견본(임시 storage · 개인 층 · M01 은 읽기만): 바탕 로직 · 옛 칸 값(더한줄 로직) · 율 더한줄 · 형제 SK(바탕 참조) ·
「따로」(수식 사본을 고쳐 저장) · 가져온 식(엑셀 줄 · 저장 없음).
걸음 2-C1(SK 셈 한 길)이 이 시험을 자로 씀 — 「따로」 단언은 지금 사실(줄 = 옛 · 기준 = 새)이고 2-C1 에서 뒤집음.
"""
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_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(doc: dict, old: bool) -> dict:
whole = m01.loaded()[1]
token = dsk.OLD.set(old)
try:
return calc.run(sd.clean(doc, None, whole), whole)
finally:
dsk.OLD.reset(token)
def _both(folder, doc) -> tuple[dict, dict]:
with store.at(folder):
return _run(doc, True), _run(doc, False)
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 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 _same_paths(old: dict, new: dict) -> None:
assert old["기준"] is not None and new["기준"] is not None
assert {k: Decimal(str(old["기준"][k])) for k in COSTS} == {
k: Decimal(str(new["기준"][k])) for k in COSTS
}
assert _lines_sum(new) == _base(new)
@pytest.mark.parametrize(
"body",
[
{"바탕": {"로직": FORM}},
{"바탕": {"로직": PCT}},
{"바탕": {"로직": FORM}, "더한줄": [ADD]}, # 옛 칸 값(더한줄 로직)
{"바탕": {"로직": SUB}, "더한줄": [_rate("인력", 2)], "단위": "주"}, # 율 더한줄
],
ids=["바탕", "율_바탕", "옛칸_더한줄", "율_더한줄"],
)
def test_층_SK_옛_대_새_같고_줄_합_기준(world, body):
me = world["personal"]
key = _sk(me, **copy.deepcopy(body))
doc = _doc(me, key)
old, new = _both(me, doc)
assert "수식셈" in new # 지금 길 = 수식 사본 문서 셈
_same_paths(old, new)
def test_형제_SK_바탕_참조(world):
me = world["personal"]
first = _sk(me, 바탕={"로직": FORM})
second = _sk(me, 바탕={"참조": {"층": "personal", "주인": "7/42", "키": first}})
old, new = _both(me, _doc(me, second))
_same_paths(old, new)
assert new["기준"] == _both(me, _doc(me, first))[1]["기준"]
def test_가져온_식_옛_대_새(world):
old, new = _both(world["personal"], imported._doc())
assert "수식셈" in new
_same_paths(old, new)
def test_따로_SK_지금은_줄_옛_기준_새(world):
"""「따로」 = 고친 수식 사본이 정본 — 지금 셈 답은 줄 = 옛 엔진(옛 칸) · 기준 = 문서 계산기라 갈림.
2-C1 에서 뒤집을 단언 — 그 뒤엔 `_same_paths` 꼴(줄 합 = 기준)로 바꿈."""
me = world["personal"]
key = _sk(me, 바탕={"로직": PCT})
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
old, new = _both(me, _doc(me, key))
assert new["수식셈"]["따로"] is True
assert _base(new) != _base(old) # 2-C1 에서 뒤집을 단언 — 기준이 옛 길과 다름
assert _lines_sum(new) == _base(old) != _base(new) # 2-C1 에서 뒤집을 단언 — 줄 = 옛 길