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,19 +1,21 @@
|
||||
"""M01 재료 기본 검색어 · 고름 · 단위 환산 · 단위 경고 — PLAN 8-1 · 8-2 계약.
|
||||
|
||||
검색어 든 견본 로직 줄을 시험 안에서 만들어(`POST /calc` 의 `row` — 저장 안 함) 돌림. 정본 폴더는 읽기만.
|
||||
재료 줄 단가 = `master_pick.priced`(문서 셈 · M02 가 같이 씀) · 기계 입력 · 품목 칸 = 수식 문서 셈.
|
||||
옛 M01 `/calc` 길(견본 로직 줄 `row`)과 엔진은 855-E 2-E4 에서 걷음. 정본 폴더는 읽기만.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import helper_855_engine as h
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
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 · 시험 전용)
|
||||
from M02_MasterTemplete import M02_Doc_Copy as dc
|
||||
|
||||
mf = store.cm.mf
|
||||
mp = mf.mp
|
||||
@@ -23,84 +25,62 @@ mp = mf.mp
|
||||
def client() -> TestClient:
|
||||
app = FastAPI()
|
||||
app.include_router(router_module.router)
|
||||
app.include_router(old_engine.router)
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
def _sample(term: str, unit: str, **cond) -> dict:
|
||||
"""재료 줄 하나짜리 견본 로직 — 검색어 줄 하나 · 수량 1."""
|
||||
return {
|
||||
"이름": "검색어 견본",
|
||||
"구분": "자체",
|
||||
"입력": [],
|
||||
"호표": [
|
||||
{
|
||||
"종류": "재료",
|
||||
"요소": {"검색어": term, **cond},
|
||||
"이름": "견본 재료",
|
||||
"단위": unit,
|
||||
"수량": "1",
|
||||
"비목": "재료비",
|
||||
}
|
||||
],
|
||||
}
|
||||
def _line(term: str, unit: str, picks: dict | None = None) -> dict:
|
||||
"""검색어 재료 줄 하나(수량 1) — {단가, 출처, 까닭, 단위경고?, 품목?}."""
|
||||
token = mp.CHOSEN.set(picks or {})
|
||||
try:
|
||||
price, source, why, extra = mp.priced(
|
||||
store.loaded()[1], {"단위": unit}, {"검색어": term}, {}, 0
|
||||
)
|
||||
finally:
|
||||
mp.CHOSEN.reset(token)
|
||||
return {"단가": price, "출처": source or "", "까닭": why, **extra}
|
||||
|
||||
|
||||
def _line(client: TestClient, row: dict, picks: dict | None = None, path: str = "calc") -> dict:
|
||||
body = {"key": "GF999999", "inputs": {}, "row": row, **({"고름": picks} if picks else {})}
|
||||
got = client.post(f"/api/m01/{path}", json=body).json()
|
||||
assert got.get("ok", True) is True, got
|
||||
return got["lines"][0] if path == "calc" else got
|
||||
def _auto(key: str) -> dict:
|
||||
whole = h.world()[0]
|
||||
return dc.auto_of(dc.doc_of(whole, key), whole)
|
||||
|
||||
|
||||
def test_검색어로_찾고_지역_낱말이_맞는_줄이_먼저(client) -> None:
|
||||
seoul = _line(client, _sample("합판(내수) 12t 서울", "㎡"))
|
||||
def test_검색어로_찾고_지역_낱말이_맞는_줄이_먼저() -> None:
|
||||
seoul = _line("합판(내수) 12t 서울", "㎡")
|
||||
assert seoul["출처"].startswith("MT000018") and seoul["단가"] == 11354 # 값 열 가운데 낮은 값
|
||||
busan = _line(client, _sample("합판(내수) 12t 부산", "㎡"))
|
||||
busan = _line("합판(내수) 12t 부산", "㎡")
|
||||
assert busan["출처"].startswith("MT000020") and busan["단가"] == 11488
|
||||
assert "단위경고" not in seoul
|
||||
|
||||
|
||||
def test_고름은_그_줄만_그_품목으로_셈(client) -> None:
|
||||
row = _sample("합판(내수) 12t 서울", "㎡")
|
||||
got = _line(client, row, {"0": "MT000019"})
|
||||
def test_고름은_그_줄만_그_품목으로_셈() -> None:
|
||||
got = _line("합판(내수) 12t 서울", "㎡", {"0": "MT000019"})
|
||||
assert got["출처"].startswith("MT000019") and got["단가"] == 11556
|
||||
assert _line(client, row)["단가"] == 11354 # 요청마다 — 저장 안 함
|
||||
text = _line(client, row, {"0": "MT000019"}, "text")
|
||||
assert text["ok"] is True # 읽는 식도 같은 몸으로 돎
|
||||
assert _line("합판(내수) 12t 서울", "㎡")["단가"] == 11354 # 요청마다 — 저장 안 함
|
||||
|
||||
|
||||
def test_같은_성격_단위는_줄_단위로_환산(client) -> None:
|
||||
got = _line(client, _sample("어닐링철선 서울 4.0mm", "톤")) # 자재 kg → 줄 톤
|
||||
def test_같은_성격_단위는_줄_단위로_환산() -> None:
|
||||
got = _line("어닐링철선 서울 4.0mm", "톤") # 자재 kg → 줄 톤
|
||||
assert got["단가"] == 1610000 and "단위경고" not in got
|
||||
got = _line(client, _sample("어닐링철선 서울 4.0mm", "g"))
|
||||
assert got["단가"] == pytest.approx(1.61)
|
||||
got = _line("어닐링철선 서울 4.0mm", "g")
|
||||
assert got["단가"] == pytest.approx(Decimal("1.61"))
|
||||
|
||||
|
||||
def test_성격이_다르면_계산은_하고_단위경고(client) -> None:
|
||||
got = _line(client, _sample("어닐링철선 서울 4.0mm", "m"))
|
||||
def test_성격이_다르면_계산은_하고_단위경고() -> None:
|
||||
got = _line("어닐링철선 서울 4.0mm", "m")
|
||||
assert got["단가"] == 1610 and got["단위경고"] == "줄 m · 자재 kg"
|
||||
assert got["금액"] == 1610
|
||||
|
||||
|
||||
def test_검색어_후보가_없으면_그_줄만_비움(client) -> None:
|
||||
got = client.post(
|
||||
"/api/m01/calc", json={"key": "GF999999", "inputs": {}, "row": _sample("없는물건zzz", "개")}
|
||||
).json()
|
||||
assert got["ok"] is True and got["lines"][0]["금액"] is None
|
||||
assert "후보 없음" in got["lines"][0]["까닭"]
|
||||
def test_검색어_후보가_없으면_그_줄만_비움() -> None:
|
||||
got = _line("없는물건zzz", "개")
|
||||
assert got["단가"] is None and "후보 없음" in got["까닭"]
|
||||
|
||||
|
||||
def test_기계_입력은_목록_밖_원문번호도_받음(client) -> None:
|
||||
def test_기계_입력은_목록_밖_원문번호도_받음() -> None:
|
||||
key = "GC000267"
|
||||
inputs = {
|
||||
**old_engine.auto(key)["값"],
|
||||
"기계": "0101-0007",
|
||||
} # 고르기 목록 밖 · 기계 마스터엔 있음
|
||||
got = client.post("/api/m01/calc", json={"key": key, "inputs": inputs}).json()
|
||||
assert got["ok"] is True, got
|
||||
bad = client.post("/api/m01/calc", json={"key": key, "inputs": {**inputs, "기계": "9999-9999"}})
|
||||
assert bad.json()["ok"] is False # 기계 마스터에 없는 번호는 그대로 막힘
|
||||
inputs = {**_auto(key), "기계": "0101-0007"} # 고르기 목록 밖 · 기계 마스터엔 있음
|
||||
assert h.calc(key, inputs)["셈됨"]
|
||||
assert not h.calc(key, {**inputs, "기계": "9999-9999"})["셈됨"] # 마스터에 없는 번호 = 막힘
|
||||
|
||||
|
||||
def test_단위_환산_표() -> None:
|
||||
@@ -111,7 +91,7 @@ def test_단위_환산_표() -> None:
|
||||
assert mp.same_kind("ℓ", "㎥") and not mp.same_kind("kg", "m")
|
||||
|
||||
|
||||
def test_check_master_검색어_후보0_단위경고(client) -> None:
|
||||
def test_check_master_검색어_후보0_단위경고() -> None:
|
||||
whole = store.loaded()[1]
|
||||
assert mf.check_pick(whole, "줄", {"검색어": "합판(내수) 12t 서울"}) == []
|
||||
assert "후보 0" in mf.check_pick(whole, "줄", {"검색어": "없는물건zzz"})[0]
|
||||
@@ -119,37 +99,23 @@ def test_check_master_검색어_후보0_단위경고(client) -> None:
|
||||
assert "성격이 다름" in mf.check_unit(whole, "줄", {"검색어": "어닐링철선 서울 4.0mm"}, "m")[0]
|
||||
|
||||
|
||||
def test_기계_입력은_EQ_키도_원문번호로_풀어_받음(client) -> None:
|
||||
def test_기계_입력은_EQ_키도_원문번호로_풀어_받음() -> None:
|
||||
key = "GC000267"
|
||||
number = "0101-0007" # 고르기 목록 밖
|
||||
eq = next(k for k, r in store.loaded()[1].index["EQ"].items() if r.get("원문번호") == number)
|
||||
base = {**old_engine.auto(key)["값"]}
|
||||
by_number = client.post(
|
||||
"/api/m01/calc", json={"key": key, "inputs": {**base, "기계": number}}
|
||||
).json()
|
||||
by_key = client.post("/api/m01/calc", json={"key": key, "inputs": {**base, "기계": eq}}).json()
|
||||
assert by_key["ok"] is True, by_key
|
||||
assert by_key["sums"] == by_number["sums"] # EQ 키 = 원문번호와 같은 계산
|
||||
bad = client.post("/api/m01/calc", json={"key": key, "inputs": {**base, "기계": "EQ999999"}})
|
||||
assert bad.json()["ok"] is False
|
||||
base = _auto(key)
|
||||
by_number = h.calc(key, {**base, "기계": number})
|
||||
by_key = h.calc(key, {**base, "기계": eq})
|
||||
assert by_key["셈됨"], by_key
|
||||
assert [by_key[k] for k in h.KEYS] == [by_number[k] for k in h.KEYS] # EQ 키 = 원문번호
|
||||
assert not h.calc(key, {**base, "기계": "EQ999999"})["셈됨"]
|
||||
|
||||
|
||||
def test_재료_줄마다_품목_칸(client) -> None:
|
||||
key = "GF000160"
|
||||
body = {"key": key, "inputs": {k: str(v) for k, v in old_engine.auto(key)["값"].items()}}
|
||||
lines = client.post("/api/m01/calc", json=body).json()["lines"]
|
||||
idx = next(
|
||||
i for i, x in enumerate(lines) if x.get("품목", {}).get("이름", "").startswith("합판(내수)")
|
||||
)
|
||||
first = lines[idx]["품목"]
|
||||
assert (first["이름"], first["지역"]) == ("합판(내수)", "서울") and first[
|
||||
"값칸"
|
||||
] # 830-10 지역 칸
|
||||
assert {"키", "이름", "규격", "단위", "값칸"} <= set(first)
|
||||
lines = client.post("/api/m01/calc", json={**body, "고름": {str(idx): "MT000019"}}).json()[
|
||||
"lines"
|
||||
]
|
||||
assert lines[idx]["품목"]["키"] == "MT000019" and "인천" in lines[idx]["품목"]["지역"]
|
||||
def test_재료_줄마다_품목_칸() -> None:
|
||||
got = h.traced("GF000160")
|
||||
first = next(x["품목"] for x in got["줄"] if (x.get("품목") or {}).get("이름") == "합판(내수)")
|
||||
assert mf.mp.mm.mmerge.where(first) == "서울" and first["키"].startswith("MT") # 830-10 지역 칸
|
||||
assert {"키", "이름", "규격", "단위"} <= set(first)
|
||||
|
||||
|
||||
def test_목록_검색은_띄어쓰기를_무시(client) -> None:
|
||||
|
||||
Reference in New Issue
Block a user