Files
Aislo/resources/tester/test_857_1_workbook.py
T
eomsangdonandClaude Opus 5.5 78a2d5db85 feat(857-1): 불러오기 책 한 번 · 종류 한 말 — 일위대가 시트 없는 엑셀도 올라감 · 재료판 무효 지문 · 판 셈 M01 한 벌
- 새 M02_San_Workbook — 올린 엑셀을 한 번만 엶(시트 목록 합집합 · xls 서식 책 · 종류 가름 한 말 kind_of)
- Hopyo_Excel.read_book · Hopyo_Grid.read · San_Book.sheets · Sangeun_FromHopyo.keep 이 같은 책을 받음 · 전역 _OPENED · _open · opened · _sheets 걷음
- 종류 가름 한 말 — Hopyo_Stmate.is_stmate · San_Book.kind_of 가 Workbook.kind_of 를 씀(단가산출근거 = STmate · 단가산출 = EST)
- 올림 길(Router._upload) = 단가산출 시트가 있으면 일위대가 시트 · 호표 없음도 받음(호표 빈 목록 · 단산 목록 보임) · B09 내역서 길(read_book 기본)은 그대로 거절
- 「고를 재료」 판 = 재료판지문(M01 지문 · 별칭 · 자재 칸 포함)이 다르면 다시 셈 · 판 셈 동안 M01 한 벌(M01_MasterData_Store_Cache.steady · M01 파일 안 고침)
- 수치: 올림 때 책 열기 2 → 1 · 거창 xlsx 올림 18.0 → 9.0 초 · 판 첫 셈 거창 21.9 → 4.2 · 북부청임도 31.3 → 1.0 · 봉화 34.9 → 1.6 초(재료 종 수 같음)
- 지킴: 857-0 블록 전수 3,241 다름 0 · 올림 지문 = 뜻한 바뀜만(2016사방 · 2026수목 거절 → 올라감 · 그 갈래만 다시 뜸 · 재료표 같음)
- 시험: 새 test_857_1_workbook(책 한 번 · 종류 · 빈 호표 올림 · 판 무효 · 자국 횟수) · test_857_import_golden 「--write 올림」 갈래 하나 다시 뜨기
- 낡은 시험 고침: test_m02_hopyo_excel(일위대가 · 단가산출 둘 다 없는 책 = 400 · 단가산출만 = 200 호표 0) · test_m02_hopyo_stmate · test_741(옛 _sheets · _xlsx 부름 → 책 한 벌)

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

137 lines
5.3 KiB
Python

"""857-1 지킴 — 불러오기 책 한 번 · 종류 한 말 · 일위대가 시트 없는 엑셀 올림 ·
「고를 재료」 판 무효 지문 · 판 셈 동안 M01 한 벌(`M01_MasterData_Store_Cache.steady`).
임시 storage 개인 층 · 실무 엑셀 견본(없는 PC = 건너뜀).
"""
from __future__ import annotations
import json
import sys
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
def _path(name: str) -> Path:
p = h.sources().get(f"엑셀:{name}")
if not p or not p.exists():
pytest.skip(f"견본 없음 — {name}")
return p
def _opens(monkeypatch) -> list[str]:
import openpyxl
import xlrd
seen: list[str] = []
for mod, attr in ((openpyxl, "load_workbook"), (xlrd, "open_workbook")):
real = getattr(mod, attr)
def wrap(*a, _real=real, _tag=attr, **k):
seen.append(_tag)
return _real(*a, **k)
monkeypatch.setattr(mod, attr, wrap)
return seen
def test_종류_한_말():
from M02_MasterTemplete import M02_Hopyo_Stmate as hs
from M02_MasterTemplete import M02_San_Book as sb
from M02_MasterTemplete import M02_San_Workbook as wb
for names, kind in (
(["일위대가표", "단가산출근거"], "STmate"),
(["단가산출근거"], "STmate"),
(["일위대가", "단가산출"], "EST"),
(["일위대가"], None),
):
assert wb.kind_of(names) == kind
assert sb.kind_of(dict.fromkeys(names)) == kind
assert hs.is_stmate(names) == (kind == "STmate")
@pytest.mark.parametrize("name", ["봉화", "북부청사방"])
def test_올림_한_번에_책_한_번(monkeypatch, name):
from M02_MasterTemplete import M02_Hopyo_Router as router
path = _path(name)
seen = _opens(monkeypatch)
with h.personal():
row = router._upload(path.name, path.read_bytes(), {"id": 42, "이름": "시험"})
assert row["호표수"] > 0 and not row.get("읽기불가")
assert len(seen) == 1, seen
def test_일위대가_시트_없는_엑셀도_올라감_호표_빈_목록_단산은_보임():
from M02_MasterTemplete import M02_Hopyo_Excel as hx
from M02_MasterTemplete import M02_Hopyo_Router as router
from M02_MasterTemplete import M02_Hopyo_Store as hstore
from M02_MasterTemplete import M02_MasterTemplete_Store as store
from M02_MasterTemplete import M02_Sangeun_FromHopyo as fh
path = _path("2026수목")
data = path.read_bytes()
with pytest.raises(hx.ExcelError): # B09 내역서 길(그대로) — 일위대가 시트 없음 = 거절
hx.read_book(path.name, data)
with h.personal():
row = router._upload(path.name, data, {"id": 42, "이름": "시험"})
hp = hstore.read(store.root(), row["키"])
assert row["호표수"] == 0 and hp["호표"] == []
assert len(hp["단산"]) == 142 # 단가산출 시트 블록(둘 꼴 산근 수와 같음)
assert fh.has(store.root(), row["키"]) # 가져온 식 열기 자료 보관
def test_재료판_무효_지문_M01_이_바뀌면_다시_셈(monkeypatch):
from M02_MasterTemplete import M02_Hopyo_Router as router
from M02_MasterTemplete import M02_MasterTemplete_Store as store
from M02_MasterTemplete import M02_San_MatPick as mp
from M02_MasterTemplete import M02_Sangeun_FromHopyo as fh
path = _path("영덕계류")
with h.personal():
key = router._upload(path.name, path.read_bytes(), {"id": 42, "이름": "시험"})["키"]
first = mp.census(store.root(), key)
saved = json.loads(fh._path(store.root(), key).read_bytes())
assert saved[mp.MARK] == mp._mark() and saved[mp.CENSUS] == first
runs: list[int] = []
from M02_MasterTemplete import M02_Doc_FromNative as fn
emit = fn.emit
monkeypatch.setattr(fn, "emit", lambda *a, **k: runs.append(1) or emit(*a, **k))
assert mp.census(store.root(), key) == first and not runs # 같은 M01 = 저장본
monkeypatch.setattr(mp, "_mark", lambda: "다른 M01")
assert mp.census(store.root(), key) == first and runs # 지문 다름 = 다시 셈 · 답 같음
def test_판_셈_동안_M01_파일_자국_한_번(monkeypatch):
from M01_MasterData import M01_MasterData_Store_Cache as cache
from M02_MasterTemplete import M02_Doc_FromNative as fn
from M02_MasterTemplete import M02_Hopyo_Router as router
from M02_MasterTemplete import M02_MasterTemplete_Store as store
from M02_MasterTemplete import M02_San_MatPick as mp
from M02_MasterTemplete import M02_Sangeun_FromHopyo as fh
path = _path("영덕계류")
counts: list[int] = []
real = cache._stamps
monkeypatch.setattr(cache, "_stamps", lambda folder: counts.append(1) or real(folder))
with h.personal():
key = router._upload(path.name, path.read_bytes(), {"id": 42, "이름": "시험"})["키"]
counts.clear()
held = mp.census(store.root(), key)
with_hold = len(counts)
at = fh._path(store.root(), key)
src = fh._excel_of(at, json.loads(at.read_bytes()))
counts.clear()
for no in sorted(fn.numbers(src)): # 안 쥔 셈(지금 길) — 블록마다 자국을 다시 잼
with mp.using(None):
fn.emit(src, no)
bare = len(counts)
assert held and with_hold <= 3 < bare