- 원본 처리 근거대로 내역·일위대가 금액을 비우고 공람 방법에 따라 단가 또는 수량을 비움 - JSON 또는 원본 구조 ESTX 로 내려받기, 사본은 자동계산 꺼 빈칸 유지 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3.2 KiB
Python
78 lines
3.2 KiB
Python
"""EST 테스트 앱 공내역 파일 저장(원본 mnuFileNullSave · PrintGongMethod 0/1/2)."""
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SAMPLE = Path("C:/Dasansoft/Est Plus 2/Data/ProjectData/sample.estx")
|
|
LOAD = """
|
|
const fs = require('fs'), vm = require('vm');
|
|
const ctx = vm.createContext({ structuredClone, console });
|
|
vm.runInContext(fs.readFileSync('tools/est-test/native-blank.js', 'utf8'), ctx);
|
|
"""
|
|
|
|
|
|
def node(script: str, *args: str):
|
|
out = subprocess.check_output(["node", "-e", LOAD + script, *args], cwd=ROOT)
|
|
return json.loads(out.decode("utf-8"))
|
|
|
|
|
|
def test_methods_clear_amounts_and_chosen_values_only():
|
|
result = node("""
|
|
ctx.project = JSON.parse(fs.readFileSync('tools/est-test/sample.json', 'utf8'));
|
|
const out = vm.runInContext(`(() => {
|
|
const pick = (p) => p.tables.EstMainDat.find((r) => Number(r.GN) > 0 && Number(r.TU) > 0);
|
|
const src = pick(project), at = project.tables.EstMainDat.indexOf(src);
|
|
const r = (m) => { const b = EstBlank.make(project, m), x = b.tables.EstMainDat[at];
|
|
return [x.TC, x.NC, x.TU > 0, x.GN > 0, b.options.AutoCalc, b.name.endsWith('(공내역)'), 'id' in b]; };
|
|
const head = EstBlank.make(project, 0).tables.HeadMainDat.every((x) => !Number(x.TC) && !Number(x.TU));
|
|
const wonga = EstBlank.make(project, 2).tables.Wonga.every((x) => !Number(x.Cost));
|
|
let bad = ''; try { EstBlank.make(project, 3); } catch (e) { bad = e.message; }
|
|
return { m0: r(0), m1: r(1), m2: r(2), head, wonga, bad,
|
|
untouched: Number(src.TC) > 0 && Number(src.TU) > 0 };
|
|
})()`, ctx);
|
|
process.stdout.write(JSON.stringify(out));
|
|
""")
|
|
assert result == {
|
|
"m0": [0, 0, False, True, False, True, False],
|
|
"m1": [0, 0, True, False, False, True, False],
|
|
"m2": [0, 0, True, True, False, True, False],
|
|
"head": True,
|
|
"wonga": True,
|
|
"bad": "공내역 방법을 고르세요.",
|
|
"untouched": True,
|
|
}
|
|
|
|
|
|
def test_blank_estx_round_trip_keeps_quantities_and_clears_prices():
|
|
if not SAMPLE.exists():
|
|
pytest.skip("installed EST sample unavailable")
|
|
result = node(
|
|
"""
|
|
const imp = require('./tools/est-test/import-estx.cjs'), ex = require('./tools/est-test/export-estx.cjs');
|
|
const project = imp.importEstx(fs.readFileSync(process.argv[1]));
|
|
ctx.project = project;
|
|
const blank = vm.runInContext('EstBlank.make(project, 0)', ctx);
|
|
const back = imp.importEstx(ex.exportEstx(blank));
|
|
const rows = (p) => p.tables.EstMainDat.filter((r) => Number(r.GN) > 0);
|
|
process.stdout.write(JSON.stringify({
|
|
count: rows(back).length === rows(project).length,
|
|
quantities: rows(back).every((r, i) => Number(r.GN) === Number(rows(project)[i].GN)),
|
|
prices: back.tables.EstMainDat.every((r) => !Number(r.TU) && !Number(r.TC)),
|
|
heads: back.tables.HeadMainDat.every((r) => !Number(r.TC)),
|
|
sources: back.tables.LaborcDat.length === project.tables.LaborcDat.length,
|
|
}));
|
|
""",
|
|
str(SAMPLE),
|
|
)
|
|
assert result == {
|
|
"count": True,
|
|
"quantities": True,
|
|
"prices": True,
|
|
"heads": True,
|
|
"sources": True,
|
|
}
|