"""857-0 지킴 — 불러오기 지문(걸음 4 동안 「다름 0」 자 · 도우미 `helper_857_import`). - 블록 = 원파일 EST · STC · 실무 엑셀 블록마다 엑셀 판 · 우리 판 문서 셈(노 · 재 · 경 · 계) · 검산 판정 · 줄 이음 판정. - 올림 = 실무 엑셀을 임시 개인 층에 올림 → 거절 | 호표 목록 · 칠 · 고정 줄 · 재료 이음 표. - 재료 이음 전후 표 = 호표 길 키 대 단가산출 길 키 갈래 수(857-4 의 기준). - 기본 = 빠른 표본(`QUICK_*`) · 전수 = 환경 `S857_ALL=1` · 견본 없는 PC = 그 갈래 건너뜀(수를 글로). - 다르면 실패 + 갈래 이름 — 뜻대로 바꾼 걸음만 다시 뜸(바뀐 갈래를 커밋 글에): `S857_ALL=1 ./venv/Scripts/python.exe resources/tester/test_857_import_golden.py --write` (뒤에 「블록」 · 「올림」 = 그 갈래만) """ from __future__ import annotations import json import os import sys import warnings from pathlib import Path import pytest HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) import helper_857_import as h # noqa: E402 FILE = HERE / "golden_857_import.json" REDO = "S857_ALL=1 ./venv/Scripts/python.exe resources/tester/test_857_import_golden.py --write" ALL = os.environ.get("S857_ALL") == "1" def _want() -> dict: return json.loads(FILE.read_text("utf-8")) def _compare(got: dict[str, str], want: dict[str, str], skipped: int) -> None: if not got: pytest.skip(f"견본 없음 — 건너뜀 {skipped}") missing = sorted(k for k in got if k not in want) changed = sorted(k for k in got if k in want and want[k] != got[k]) gone = sorted(k for k in want if k not in got) if ALL and not skipped else [] assert not (missing or changed or gone), ( f"지문 다름 — 바뀜 {len(changed)} {changed[:15]} · 새 {missing[:10]} · 빠짐 {gone[:10]}" f" · 건너뜀 {skipped}\n뜻대로 바꾼 걸음이면 다시 뜸: {REDO}" ) if skipped: warnings.warn(f"견본 없어 건너뜀 {skipped}", stacklevel=2) def test_블록_두_판_검산_이음_지문_같음(): got, skipped = h.blocks(ALL) _compare(got, _want()["블록"], skipped) def test_엑셀_올림_호표_목록_칠_고정_재료_지문_같음(): got, table, skipped = h.uploads(ALL) _compare(got, _want()["올림"], skipped) want = _want()["재료표"] assert {k: v for k, v in h.mat_counts(table).items()} == {k: want[k] for k in table} if __name__ == "__main__": if "--write" not in sys.argv or not ALL: sys.exit(f"다시 뜨기 = {REDO}") only = sys.argv[sys.argv.index("--write") + 1 :] # 갈래 하나만(블록 | 올림) · 없으면 둘 다 blocks, skip_b = (_want()["블록"], 0) if only == ["올림"] else h.blocks(True) ups, table, skip_u = h.uploads(True) if only != ["블록"] else (_want()["올림"], None, 0) mats = h.mat_counts(table) if table is not None else _want()["재료표"] body = {"판": 1, "블록": blocks, "올림": ups, "재료표": mats} FILE.write_text( json.dumps(body, ensure_ascii=False, indent=1, sort_keys=True) + "\n", "utf-8", newline="\n" ) print(f"블록 {len(blocks)} · 올림 {len(ups)} · 건너뜀 {skip_b + skip_u} → {FILE.name}")