Files
Aislo/resources/tester/test_714_2_calc_sheet.py
T
2026-11-01 16:39:11 +09:00

87 lines
4.6 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.
"""714-2 공용 단가산출 계산서 지킴 시험 — 글 · 순수 함수(화면 · 서버 없음).
- 704-2 M02 계산서 보기 · M01 「인력·재료·경비」 보기가 한 벌(`A00_Common/calc_sheet.ts`)을 씀
- 계산서는 부품 상자만(날 단추 · 입력 · 표 없음) · 화면에서 다시 셈 안 함(값 = 서버)
"""
import json
import shutil
import subprocess
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[2]
SHEET = ROOT / "A00_Common" / "calc_sheet.ts"
def _text(p: Path) -> str:
return p.read_text(encoding="utf-8")
def test_한_벌을_씀():
m02 = _text(ROOT / "M02_MasterTemplete" / "M02_MasterTemplete_Labor_Sheet.ts")
est = _text(ROOT / "M01_MasterData" / "M01_MasterData_UI_LogicLab_Est.ts")
detail = _text(ROOT / "M01_MasterData" / "M01_MasterData_UI_LogicLab_Detail.ts")
assert "calcSheetRows(" in m02 and "createCalcFormulaRow" not in m02
assert "calcSheetRows(" in est and "buildEst(" in detail
def test_부품_상자만():
s = _text(SHEET)
assert "<button" not in s and "document.createElement" not in s and "<table" not in s
assert "@ui/ui_template_calc_row" in s and "@ui/ui_template_input" in s
# 장비 펼침 = 서버 「펼침」(714-1b · 부른 기계경비 로직 시간당 줄) 먼저 · 그 뒤 노 · 재 · 경 몫 식
assert "x.줄.펼침" in s and "unfold.줄.map(" in s
@pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없음")
def test_식_글():
s = _text(SHEET)
pure = s[s.index("/* ── 순수 셈 ── */") : s.index("/* ── 순수 셈 끝 ── */")]
body = 'console.log(JSON.stringify([sheetFormula("268,908 * 0.12 = 32,269"), sheetFormula("59,020 * 1 * 8 / 165 = 2,862"), sheetFormula("")]))'
out = subprocess.run(
["node", "--experimental-strip-types", "--no-warnings",
"--input-type=module-typescript", "-e", pure + "\n" + body],
capture_output=True, text=True, encoding="utf-8", timeout=60,
) # fmt: skip
assert out.returncode == 0, out.stderr
assert json.loads(out.stdout) == ["268,908 × 0.12", "59,020 × 1 × 8 / 165", ""]
@pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없음")
def test_묶음_장비_한_줄():
s = _text(SHEET)
pure = s[s.index("/* ── 순수 셈 ── */") : s.index("/* ── 순수 셈 끝 ── */")]
body = """
const eq = (n, a, 쓰는입력 = []) => ({ 이름: n, 글: "", 금액: a, 묶음: "경비", 장비: true, 쓰는입력, 기준단위: "일" });
const groups = [
{ 비목: "노무비", 소계: 0, 줄: [
{ 이름: "포설공", 글: "", 금액: 10, 묶음: "인력", 쓰는입력: [] },
eq("굴착기", 100, ["지역"]), eq("굴착기", 7),
{ 이름: "보통인부", 글: "", 금액: 5, 묶음: "인력", 쓰는입력: ["두께"], 기준단위: "10㎡", 환산근거: "10㎡당 → 1㎡당 ÷10" } ] },
{ 비목: "재료비", 소계: 0, 줄: [ eq("굴착기", 20), eq("굴착기", 2), { 이름: "모래", 글: "", 금액: 3 } ] },
{ 비목: "경비", 소계: 0, 줄: [ eq("굴착기", 30), eq("굴착기", null), { 이름: "공구손료", 글: "", 금액: 1, 묶음: "경비" } ] },
];
const got = bundleLines(groups).map((b) => ({ 묶음: b.묶음, 소계: b.소계, 쓰는입력: b.쓰는입력, 기준단위: b.기준단위, 환산근거: b.환산근거,
줄: b.줄.map((l) => "몫" in l ? [l.이름, l.금액, l.몫.map((x) => x.비목)] : l.이름) }));
console.log(JSON.stringify(got));
"""
out = subprocess.run(
["node", "--experimental-strip-types", "--no-warnings",
"--input-type=module-typescript", "-e", pure + chr(10) + body],
capture_output=True, text=True, encoding="utf-8", timeout=60,
) # fmt: skip
assert out.returncode == 0, out.stderr
got = json.loads(out.stdout)
# 차례 = 인력 · 재료 · 경비 · 같은 이름 장비 둘은 k 번째끼리 한 줄(노 · 재 · 경 몫) · 비목 노무비 장비는 경비(장비) 묶음
assert [b["묶음"] for b in got] == ["인력", "재료", "경비"]
assert got[0]["줄"] == ["포설공", "보통인부"] and got[0]["소계"] == 15
assert got[0]["쓰는입력"] == ["두께"] and got[0]["기준단위"] == ["10㎡"]
assert got[0]["환산근거"] == ["10㎡당 → 1㎡당 ÷10"]
assert got[1]["줄"] == ["모래"]
eq = got[2]
assert eq["줄"][0] == ["굴착기", 150, ["노무비", "재료비", "경비"]]
assert eq["줄"][1] == ["굴착기", 9, ["노무비", "재료비", "경비"]]
assert eq["줄"][2] == "공구손료" and eq["소계"] == 160 and eq["쓰는입력"] == ["지역"]