Files
Aislo/resources/tester/test_est_quantity_sheets.py
T
eomsangdonandClaude Opus 5.5 e7e59fc513 feat(est-test): 수량산출서 복사와 순서 이동
- 현재 산출서 아래에 복사본 추가, 내역 연결은 비워 이중 반영 방지
- 산출서 위로·아래로, 순서 변경 ESTX 저장은 명확한 문구로 거부
- 단추 지킴 시험이 cjs 화면 파일도 검사

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:04:11 +09:00

75 lines
2.9 KiB
Python

"""EST 테스트 앱 수량산출서 복사·순서 이동과 ESTX 저장 거부."""
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")
LOAD = """
const fs = require('fs'), vm = require('vm');
const ctx = vm.createContext({ structuredClone, console });
vm.runInContext(fs.readFileSync('tools/est-test/native-quantity-sheets.js', 'utf8'), ctx);
const run = (code) => vm.runInContext(code, 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_copy_inserts_below_with_new_code_and_cleared_links():
result = node("""
ctx.project = { quantitySheets: [
{ Code: 'A', Name: '토공', items: [{ Code: 'r000000', TargetCode: 'D1', TargetKey: 'id:3', LinkCode: 'D1' }], rows: [{ LineData: 'x', markers: ['r000000'] }] },
{ Code: 'B', Name: '포장', items: [], rows: [] },
] };
const first = run("EstQuantitySheets.copy(project, 'A', 'u1')");
const second = run("EstQuantitySheets.copy(project, 'A', 'u1')");
const p = ctx.project;
process.stdout.write(JSON.stringify({
first, second, order: p.quantitySheets.map((s) => s.Code), name: p.quantitySheets[1].Name,
link: p.quantitySheets[1].items[0], original: p.quantitySheets[0].items[0].TargetCode,
rows: p.quantitySheets[1].rows[0].markers,
}));
""")
assert result == {
"first": "Qu1",
"second": "Qu1_2",
"order": ["A", "Qu1_2", "Qu1", "B"],
"name": "토공 복사본",
"link": {"Code": "r000000", "TargetCode": "", "TargetKey": ""},
"original": "D1",
"rows": ["r000000"],
}
def test_move_swaps_and_stops_at_edges():
result = node("""
ctx.project = { quantitySheets: [{ Code: 'A' }, { Code: 'B' }, { Code: 'C' }] };
const out = [run("EstQuantitySheets.move(project, 'B', -1)"), run("EstQuantitySheets.move(project, 'B', -1)"),
run("EstQuantitySheets.move(project, 'C', 1)")];
process.stdout.write(JSON.stringify({ out, order: ctx.project.quantitySheets.map((s) => s.Code) }));
""")
assert result == {"out": [True, False, False], "order": ["B", "A", "C"]}
def test_estx_export_refuses_reordered_sheets():
if not MAIN.exists():
pytest.skip("installed EST main sample unavailable")
result = node(
"""
const imp = require('./tools/est-test/import-estx.cjs'), ex = require('./tools/est-test/export-estx.cjs');
ctx.project = imp.importEstx(fs.readFileSync(process.argv[1]));
run("EstQuantitySheets.move(project, project.quantitySheets[0].Code, 1)");
let message = '';
try { ex.exportEstx(ctx.project); } catch (e) { message = e.message; }
process.stdout.write(JSON.stringify(message));
""",
str(MAIN),
)
assert result.startswith("수량산출서 순서 변경은 ESTX")