test(855-E 2-E4 ㉯-2): 옛 M01 셈 길 도우미 은퇴 · test_m01_* 를 문서 셈 · 바탕으로
- helper_855_old_engine_routes git rm — 2-E1 에서 서버에서 걷은 /calc · /text · /logic/auto 몸(시험 전용) · 부르는 곳 0 - test_m01_text git rm — 옛 계산서 글 엔진(master_text · master_copy) 자체만 봄(로직 줄 0 이면 빈 통과) · 계산서 글 = 문서 글(master_doc_text · test_855_c4_doc_text) - test_m01_auto: 자동값 = 문서 자동값(Doc_Copy.auto_of) · 견본 금액 · 빈 줄 · 원 입력 · 체인톱 품목 = 문서 셈(셈 기록) · 고름 = Labor_Copy.line · 없는 로직 = 문서 없음(14 통과) - test_m01_pick: 검색어 · 지역 낱말 · 고름 · 단위 환산 · 단위 경고 · 후보 없음 = master_pick.priced(문서 셈이 쓰는 바탕) · 기계 입력(목록 밖 · EQ 키) = 문서 셈 · 품목 칸 = 셈 기록 - test_m01_api: 셈 = 임시 사본 색인 문서 셈 · 저장 뒤 +40 원 · 옛 길 고유 뜻(글자 수 받기 · 모르는 입력 · 저장 전 로직 줄 시험계산) 지움 · 전력 입력 = 문서 변수 - test_m01_make: 견본 로직 줄 끝수 묶음(옛 /calc row) · check_logic 끝수 모양 검사 지움 - test_m01_cache: 목록 막힘 = 문서 막힘(master_doc_block.reasons) 전수 · 요소 지도 = 문서 막힘으로 같은 단언 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
"""M01 마스터 데이터 API — 계약 `resources/master_data/_화면_계약.md`.
|
||||
|
||||
임시 폴더에 master_data 첫 층 JSON 사본을 두고 읽기 · 시험 계산 · 저장 · 409 · 422.
|
||||
임시 폴더에 master_data 첫 층 JSON 사본을 두고 읽기 · 셈(수식 문서) · 저장 · 409 · 422.
|
||||
옛 M01 `/calc` · `/text` 길(엔진 · 글자 수 받기 · 저장 전 로직 줄 시험계산)은 855-E 2-E4 에서 걷음.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import json
|
||||
import shutil
|
||||
from decimal import Decimal
|
||||
@@ -17,7 +19,6 @@ from fastapi.testclient import TestClient
|
||||
|
||||
from M01_MasterData import M01_MasterData_Router as router_module
|
||||
from M01_MasterData import M01_MasterData_Store as store
|
||||
import helper_855_old_engine_routes as old_engine # noqa: E402 — 옛 셈 길 몸(855 2-E1 · 시험 전용)
|
||||
|
||||
REAL = store.FOLDER
|
||||
LABOR = "인력.json"
|
||||
@@ -52,7 +53,6 @@ def client(tmp_path: Path, monkeypatch) -> TestClient:
|
||||
monkeypatch.setattr(store._docs().ml, "FOLDER", tmp_path / "수식문서")
|
||||
app = FastAPI()
|
||||
app.include_router(router_module.router)
|
||||
app.include_router(old_engine.router)
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@@ -62,19 +62,16 @@ def _get(client: TestClient, url: str, **params) -> dict:
|
||||
return res.json()
|
||||
|
||||
|
||||
def _row(file: str, key: str) -> dict:
|
||||
"""옛 로직 줄(같이 쓰기 사본) — `/logic` 답은 머리만(855 L3 ⓐ) · 옛 셈 길 시험 몫."""
|
||||
rows = json.loads((store.FOLDER / file).read_text(encoding="utf-8"))["줄"]
|
||||
return next(r for r in rows if r["키"] == key)
|
||||
|
||||
|
||||
def _calc(client: TestClient, **inputs) -> dict:
|
||||
res = client.post(
|
||||
"/api/m01/calc",
|
||||
json={"key": LOGIC_KEY, "inputs": {**LOGIC_INPUTS, **inputs}},
|
||||
def _calc(**inputs) -> dict:
|
||||
"""문서 셈 — 지금 `store.FOLDER`(임시 사본) 색인 · 수식 문서."""
|
||||
ml = store._docs().ml
|
||||
docs = ml.load_all()
|
||||
links = ml.Links(store.loaded()[1], docs)
|
||||
got = importlib.import_module("master_doc_calc").calc(
|
||||
docs[LOGIC_KEY], links, {**LOGIC_INPUTS, **inputs}
|
||||
)
|
||||
assert res.status_code == 200, res.text
|
||||
return res.json()
|
||||
assert got["셈됨"], got
|
||||
return got
|
||||
|
||||
|
||||
def _labor_row(client: TestClient, number: str) -> tuple[dict, str]:
|
||||
@@ -168,21 +165,18 @@ def test_로직_목록_하나_시험계산(client: TestClient) -> None:
|
||||
assert _get(client, "/api/m01/logics", blocked=1)["logics"] == []
|
||||
one = _get(client, "/api/m01/logic", key=LOGIC_KEY)
|
||||
assert one["file"] == "로직_건설품셈_03장_토공사.json" and one["blocked"] is False
|
||||
got = _calc(client)
|
||||
assert got["ok"] is True
|
||||
lines = {x["이름"]: x for x in got["lines"]}
|
||||
got = _calc()
|
||||
lines = {x["이름"]: x for x in got["줄"]}
|
||||
one = lines["화약취급공"] # 751-3 — 줄 0.1 원 · 비목 합 1 원 버림
|
||||
raw = Decimal(str(one["수량"])) * Decimal(str(one["단가"]))
|
||||
assert Decimal(str(one["금액"])) == Decimal(str(int(raw * 10))) / 10
|
||||
gap = sum(x["금액"] for x in got["lines"]) - got["sums"]["계"]
|
||||
assert -1e-6 <= gap < 3
|
||||
stop = _calc(client, 없는입력=1)
|
||||
assert stop["ok"] is False and "모르는 입력" in stop["reason"]
|
||||
gap = sum(x["금액"] for x in got["줄"]) - got["계"]
|
||||
assert 0 <= gap < 3
|
||||
|
||||
|
||||
def test_저장_고침은_파일에_쓰고_낡은_판본은_409(client: TestClient) -> None:
|
||||
row, version = _labor_row(client, "1016")
|
||||
before = _calc(client)["sums"]["계"]
|
||||
before = _calc()["계"]
|
||||
edited = {**row, "값": row["값"] + 1000}
|
||||
body = {
|
||||
"files": [
|
||||
@@ -198,7 +192,9 @@ def test_저장_고침은_파일에_쓰고_낡은_판본은_409(client: TestClie
|
||||
new_version = res.json()["files"][0]["version"]
|
||||
assert new_version != version
|
||||
assert _labor_row(client, "1016") == (edited, new_version)
|
||||
assert _calc(client)["sums"]["계"] == pytest.approx(before + 1000 * 0.04) # 화약취급공 0.040 인
|
||||
assert _calc()["계"] == pytest.approx(
|
||||
before + 1000 * Decimal("0.04"), abs=1
|
||||
) # 화약취급공 0.040 인
|
||||
data = json.loads((store.FOLDER / LABOR).read_text(encoding="utf-8"))
|
||||
assert (
|
||||
data["그룹"] == "인력"
|
||||
@@ -262,34 +258,11 @@ def test_요소_찾기_기계는_구분_상세구분_실림(client: TestClient)
|
||||
assert all(x["구분"] and x["상세구분"] for x in found["items"])
|
||||
|
||||
|
||||
def test_단가_자동_요소_찾기_저장전_시험계산(client: TestClient) -> None:
|
||||
one = _get(client, "/api/m01/logic", key=LOGIC_KEY)
|
||||
def test_단가_자동_요소_찾기(client: TestClient) -> None:
|
||||
found = _get(client, "/api/m01/elements", group="인력", q="보통인부")
|
||||
assert key_of("LB:1002") in [x["ref"] for x in found["items"]]
|
||||
tables = _get(client, "/api/m01/elements", group="소요량", q="암발파", limit=5)
|
||||
assert tables["items"] and all(x["값칸"] for x in tables["items"])
|
||||
raw = (store.FOLDER / one["file"]).read_bytes()
|
||||
before = _calc(client)["sums"]["계"]
|
||||
row = _row(one["file"], LOGIC_KEY)
|
||||
half = {**row, "호표": row["호표"][:1]} # 보통인부 줄 뺌
|
||||
res = client.post(
|
||||
"/api/m01/calc",
|
||||
json={"key": LOGIC_KEY, "inputs": LOGIC_INPUTS, "row": half},
|
||||
)
|
||||
lines = res.json()["lines"]
|
||||
names = [x["이름"] for x in lines] # 소모자재 덧줄(3-3-6 주⑨)은 남음
|
||||
assert (
|
||||
names[0] == "화약취급공" and "보통인부" not in names and res.json()["sums"]["계"] < before
|
||||
)
|
||||
new = {**half, "키": "", "원문번호": "새 로직"}
|
||||
body = {
|
||||
"key": "",
|
||||
"inputs": LOGIC_INPUTS,
|
||||
"row": new,
|
||||
"file": one["file"],
|
||||
}
|
||||
assert client.post("/api/m01/calc", json=body).json()["ok"] is True
|
||||
assert (store.FOLDER / one["file"]).read_bytes() == raw # 시험 계산은 안 씀
|
||||
|
||||
|
||||
def test_쓰기_모양은_읽은_값과_같음() -> None:
|
||||
@@ -304,18 +277,6 @@ def test_쓰기_모양은_읽은_값과_같음() -> None:
|
||||
assert "\r" not in text and text.endswith("}\n")
|
||||
|
||||
|
||||
def test_시험계산_글로_온_수도_받음(client: TestClient) -> None:
|
||||
def calc(**inputs):
|
||||
body = {"key": key_of("GF000219"), "inputs": inputs}
|
||||
return client.post("/api/m01/calc", json=body).json()
|
||||
|
||||
base = {"돌": "견치돌", "쌓기": "골쌓기", "높이": 1, "초과증가율": 80}
|
||||
assert calc(뒷길이=35, **base)["sums"]["계"] == pytest.approx(203281.2)
|
||||
as_text = calc(**{**base, "뒷길이": "35", "높이": "1"})
|
||||
assert as_text["ok"] is True and as_text["sums"]["계"] == pytest.approx(203281.2)
|
||||
assert "고르기 밖" in calc(뒷길이="36", **base)["reason"]
|
||||
|
||||
|
||||
def test_저장은_고친_줄만_바꿈(client: TestClient) -> None:
|
||||
old = (store.FOLDER / LABOR).read_text(encoding="utf-8").split("\n")
|
||||
row, version = _labor_row(client, "1016")
|
||||
@@ -381,9 +342,9 @@ def test_구분_목록(client: TestClient) -> None:
|
||||
def test_전력은_계약종별을_골라야_값이_섬(client: TestClient) -> None:
|
||||
"""후보 조건 「계약종별: 입력」(PLAN 7-4b 뒤 절반 — 품셈재료 간접 없이 호표에 바로 박음) —
|
||||
계산은 로직 입력으로 값이 섬(mf.element 로 직접 확인)."""
|
||||
one = _get(client, "/api/m01/logic", key=key_of("GC000893"))
|
||||
one = _get(client, "/api/m01/logic", key="GC000893")
|
||||
cond = {"이름": "전력량요금", "계약종별": "입력"}
|
||||
assert "전력 계약종별" in {x["이름"] for x in _row(one["file"], one["logic"]["키"])["입력"]}
|
||||
assert "전력 계약종별" in {v["열쇠"] for v in store._docs().docs()[one["logic"]["키"]]["변수"]}
|
||||
with pytest.raises(store.cm.mf.FormulaError, match="전력 계약종별"):
|
||||
store.cm.mf.element(store.cm.master(), cond, {})
|
||||
value, source = store.cm.mf.element(store.cm.master(), cond, {"전력 계약종별": "주택용 저압"})
|
||||
|
||||
Reference in New Issue
Block a user