Files
Aislo/resources/tester/test_m01_pick.py
T
eomsangdonandClaude Opus 5.5 548fc3d00a 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>
2026-11-18 15:15:49 +09:00

125 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""M01 재료 기본 검색어 · 고름 · 단위 환산 · 단위 경고 — PLAN 8-1 · 8-2 계약.
재료 줄 단가 = `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
from M02_MasterTemplete import M02_Doc_Copy as dc
mf = store.cm.mf
mp = mf.mp
@pytest.fixture(scope="module")
def client() -> TestClient:
app = FastAPI()
app.include_router(router_module.router)
return TestClient(app)
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 _auto(key: str) -> dict:
whole = h.world()[0]
return dc.auto_of(dc.doc_of(whole, key), whole)
def test_검색어로_찾고_지역_낱말이_맞는_줄이_먼저() -> None:
seoul = _line("합판(내수) 12t 서울", "㎡")
assert seoul["출처"].startswith("MT000018") and seoul["단가"] == 11354 # 값 열 가운데 낮은 값
busan = _line("합판(내수) 12t 부산", "㎡")
assert busan["출처"].startswith("MT000020") and busan["단가"] == 11488
assert "단위경고" not in seoul
def test_고름은_그_줄만_그_품목으로_셈() -> None:
got = _line("합판(내수) 12t 서울", "㎡", {"0": "MT000019"})
assert got["출처"].startswith("MT000019") and got["단가"] == 11556
assert _line("합판(내수) 12t 서울", "㎡")["단가"] == 11354 # 요청마다 — 저장 안 함
def test_같은_성격_단위는_줄_단위로_환산() -> None:
got = _line("어닐링철선 서울 4.0mm", "톤") # 자재 kg → 줄 톤
assert got["단가"] == 1610000 and "단위경고" not in got
got = _line("어닐링철선 서울 4.0mm", "g")
assert got["단가"] == pytest.approx(Decimal("1.61"))
def test_성격이_다르면_계산은_하고_단위경고() -> None:
got = _line("어닐링철선 서울 4.0mm", "m")
assert got["단가"] == 1610 and got["단위경고"] == "줄 m · 자재 kg"
def test_검색어_후보가_없으면_그_줄만_비움() -> None:
got = _line("없는물건zzz", "개")
assert got["단가"] is None and "후보 없음" in got["까닭"]
def test_기계_입력은_목록_밖_원문번호도_받음() -> None:
key = "GC000267"
inputs = {**_auto(key), "기계": "0101-0007"} # 고르기 목록 밖 · 기계 마스터엔 있음
assert h.calc(key, inputs)["셈됨"]
assert not h.calc(key, {**inputs, "기계": "9999-9999"})["셈됨"] # 마스터에 없는 번호 = 막힘
def test_단위_환산_표() -> None:
assert mp.convert(Decimal(1610), "kg", "톤") == 1610000
assert mp.convert(Decimal(5), "Ton", "kg") == Decimal("0.005")
assert mp.convert(Decimal(100), "㎡", "㎠") == Decimal("0.01")
assert mp.convert(Decimal(7), "kg", "m") == 7 # 성격이 다르면 그대로
assert mp.same_kind("ℓ", "㎥") and not mp.same_kind("kg", "m")
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]
assert mf.check_unit(whole, "줄", {"검색어": "어닐링철선 서울 4.0mm"}, "kg") == []
assert "성격이 다름" in mf.check_unit(whole, "줄", {"검색어": "어닐링철선 서울 4.0mm"}, "m")[0]
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 = _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_재료_줄마다_품목_칸() -> 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:
for q in ("함석", "골 함 석", "골함석"):
got = client.get("/api/m01/rows", params={"file": "재료_자재품목.json", "q": q}).json()
assert any(r["이름"] == "골 함 석" for r in got["rows"]), q