# -*- coding: utf-8 -*- """PLAN 854-3 — 기계 칸 단위 표 셋 거울: 화면(`common_util_line_stack_unit.ts` MACHINE_UNIT) · 내 기계(`M02_MyMachine.UNITS`) · 기계 표 빌더(`build_기계_건설품셈.UNIT`). 같은 칸 이름은 단위가 같음 — 화면 표시용 글자 바꿈(kWh → ㎾h)만 규칙으로 봄 · 빌더의 「주연료의 %」 는 설명 붙은 % 라 % 로 봄. 세 표 어디에도 없는 TS 칸은 시간당 금액 칸(노무비 · 재료비 · 경비)뿐. """ from __future__ import annotations import importlib import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(ROOT / "resources" / "master_data" / "scripts")) from M02_MasterTemplete import M02_MyMachine as my # noqa: E402 build = importlib.import_module("build_기계_건설품셈") MONEY_ONLY_TS = {"노무비", "재료비", "경비"} def _ts_table() -> dict[str, str]: src = (ROOT / "common_util" / "common_util_line_stack_unit.ts").read_text(encoding="utf-8") body = re.search(r"MACHINE_UNIT: Record = \{(.*?)\n\};", src, re.S) assert body, "MACHINE_UNIT 표를 못 찾음" return dict(re.findall(r'^\s*([^\s:]+): "([^"]*)",?$', body.group(1), re.M)) def _screen(unit: str) -> str: # 화면 표시용 글자 바꿈 — 파이썬 글 → 화면 글 return unit.replace("kWh", "㎾h").replace("주연료의 %", "%") def test_machine_unit_tables_mirror() -> None: ts = _ts_table() assert len(ts) == 16 py = {"내 기계": my.UNITS, "빌더": build.UNIT} for name, table in py.items(): for col, unit in table.items(): if not unit: # 무차원 = 화면 표 밖 continue assert col in ts, f"{name} 칸 「{col}」 이 화면 표에 없음" assert ts[col] == _screen(unit), f"{name} 「{col}」 단위 {unit!r} ≠ 화면 {ts[col]!r}" for col in ts: assert col in MONEY_ONLY_TS or any(col in t for t in py.values()), ( f"화면 칸 「{col}」 짝 없음" )