Files
Aislo/resources/tester/test_est_row_links.py
T

54 lines
2.8 KiB
Python

"""EST 테스트 앱 줄 연결 도구(원본 비목별 단가 불러오기 · SUM 색인지정 · 하위데이타 연결/끊기)."""
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
def run_js(code: str):
runner = f"""
const fs = require('fs'), vm = require('vm');
const ctx = vm.createContext({{ structuredClone }});
for (const f of ['native-autolink.js', 'native-row-links.js'])
vm.runInContext(fs.readFileSync('tools/est-test/' + f, 'utf8'), ctx, {{ filename: f }});
process.stdout.write(JSON.stringify(vm.runInContext({json.dumps(code)}, ctx)));
"""
return json.loads(subprocess.check_output(["node", "-e", runner], cwd=ROOT).decode("utf-8"))
def test_cost_part_sum_index_and_toggle():
out = run_js(
r"""(() => {
const L = EstRowLinks, p = { tables: {
CostTitleDat: [{ Code: 'D1', Name: '거푸집', Size: '합판', Unite: 'm2', TC: 60, NC: 40, GC: 15, JC: 5, SC: 0 }],
StuffcDat: [{ Code: 'M1', Name: '시멘트', Size: '40kg', Unite: '포', TC: 5000, GC: 5000 }],
LaborcDat: [], HeadTitleDat: [], MachTitleDat: [], SilJukDat: [], EstiMateDat: [] } };
const r = { LinkIndex: 104, Code: 'D1', NU: 1, GU: 1, JU: 1, SU: 1, TU: 9 };
L.costPart(p, r, 3);
const jc = [r.NU, r.GU, r.JU, r.SU, r.OCheck, r.TU];
L.costPart(p, r, 0);
const all = [r.NU, r.GU, r.JU, r.OCheck];
let refused = ''; try { L.costPart(p, { LinkIndex: 5 }, 0); } catch (e) { refused = e.message; }
const est = { Code: '', Name: '시멘트', Size: '40kg', Unite: '포', LinkIndex: 0 };
const linked = [L.toggle(p, 'EstMainDat', est), est.Code, est.LinkIndex, est.GU, est.TU];
const unlinked = [L.toggle(p, 'EstMainDat', est), est.LinkIndex, est.Code];
let none = ''; try { L.toggle(p, 'EstMainDat', { Name: '없음', LinkIndex: 0 }); } catch (e) { none = e.message; }
const skip = L.toggle(p, 'EstMainDat', { LinkIndex: 54 });
const s = { LinkIndex: 0, Index: 0 }; L.sumIndex('EstMainDat', s, 3);
const bad = []; for (const row of [{ Level: 1, GN: 0 }, { LinkIndex: 53 }, { Index: 1 }])
try { L.sumIndex('EstMainDat', row, 1); } catch (e) { bad.push(e.message.slice(0, 6)); }
return { jc, all, refused, linked, unlinked, none, skip, skind: s.SKind, bad };
})()"""
)
assert out["jc"] == [0, 0, 5, 0, 3, 9]
assert out["all"] == [40, 15, 5, 0]
assert out["refused"] == "노임,자재,표준시장단가는 적용할수 없습니다."
assert out["linked"] == ["link", "M1", 5, 5000, 5000]
assert out["unlinked"] == ["unlink", 0, "M1"]
assert out["none"] == "해당 하위data를 찾지못해 연결시키지 못했습니다."
assert out["skip"] == "skip"
assert out["skind"] == 3
assert out["bad"] == ["레벨지정한 ", "현재라인의 ", "현재라인의 "]