"""EST 테스트 앱 워드형 수량산출서 표(원본 WPT 보존 · 방향 셀 합 · 수량 표지 · 세로 병합).""" import json import subprocess from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[2] MAIN = Path("C:/Dasansoft/Est Plus 2/Data/ProjectData/main.estx") def node(code: str, *args: str): return json.loads( subprocess.check_output(["node", "-e", code, *args], cwd=ROOT).decode("utf-8") ) def test_table_parse_sum_values_merge(): out = node(r""" const W = require(process.cwd() + '/tools/est-test/native-quantity-wpt.cjs'); const wpt = '' + '
단가 9
' + '
' + '' + '
공종수량
절단1,000.5
깨기2
계
'; const s = W.fromWpt('N1', '시험', wpt, [], {}); const t = s.rows[1].table; const div = s.rows[0].LineData; t[3][1].formula = W.sumFormula(t, 3, 1, 'down'); const values = Object.fromEntries(W.values(s)); const right = W.sumFormula(t, 3, 1, 'right'); W.vmerge(t, 1, 2, 0); const merged = [t[1][0].text, t[2][0].vmerge, t[1][0].vtop]; W.vsplit(t, 1, 0); process.stdout.write(JSON.stringify({ rows: s.rows.length, div, cell: t[1][1], name: t[1][0].name, formula: t[3][1].formula, sum: t[3][1].text, values, right, merged, split: t[2][0].vmerge ?? null, created: W.create(2, 3).map((r) => r.length) })); """) assert out["rows"] == 2 assert out["div"] == "단가 9" # 문단의 G 표지는 표지로 보지 않음 assert out["cell"] == {"text": "1,000.5", "mark": "G00000203"} assert out["name"] is True assert out["formula"] == "SUM(B2:B3)" and out["sum"] == "1,002.5" assert out["values"] == {"G00000203": 1000.5} assert out["right"] == "SUM(A4:A4)" assert out["merged"] == ["절단 깨기", True, 2] assert out["split"] is None assert out["created"] == [3, 3] def test_installed_main_tables_survive_import(): if not MAIN.exists(): pytest.skip("installed EST main sample unavailable") out = node( r""" const { importEstx } = require(process.cwd() + '/tools/est-test/import-estx.cjs'); const p = importEstx(require('fs').readFileSync(process.argv[1])); const tables = p.quantitySheets.filter((s) => s.rows.some((r) => r.table)) .map((s) => { const t = s.rows.find((r) => r.table).table; return [s.Code, t.length, t[0].length]; }); process.stdout.write(JSON.stringify(tables)); """, str(MAIN), ) assert out == [ ["N0000000097", 9, 13], ["N0000000108", 7, 5], ["N0000000109", 5, 5], ["N0000000110", 7, 5], ["N0000000111", 8, 5], ]