"""139-1 관 보호공 높이 = 관경 + 0.5 — 화면 쪽(새 관 기본값 · 폼 읽기 옮김 · 관경 따라감). - B05 `optionDefaults` → `fillPipeHeights`: 새 관 높이 칸 셋(유입 · 유출 흙막이 · 유입 집수정) = 관경 + 0.5. - 폼 `followPipeHeights`(둘 다 `common_util_culvert_sets.ts`): 읽을 때 옛 1.5 · 관경 > 1.0 → 관경 + 0.5 · 관경을 바꾸면 옛 규칙 값 · 옛 1.5 칸만 따라감(손 값 · 빈 칸 그대로). """ from __future__ import annotations import json import subprocess from pathlib import Path import pytest ROOT = Path(__file__).resolve().parents[2] TSC = ROOT / "config" / "node_modules" / "typescript" / "bin" / "tsc" _RUNNER = """ import { writeFileSync } from "node:fs"; import { fillPipeHeights, followPipeHeights } from "./common_util_culvert_sets.js"; const keys = ["pipe_diameter_mm", "inlet_revet_height_m", "outlet_revet_height_m", "inlet_basin_height_m"]; const fresh = { pipe_diameter_mm: 1200 }; fillPipeHeights(fresh, keys); const noPipe = {}; fillPipeHeights(noPipe, keys); const st = (d, i, o) => ({ pipe: [{ diameter: d }], inlet: [{ height: i }], outlet: [{ height: o }] }); const read = st("1200", "1.5", "1.6"); followPipeHeights(read, "1200"); const small = st("800", "1.5", ""); followPipeHeights(small, "800"); const change = st("1200", "1.7", "2.2"); followPipeHeights(change, "1500", "1200"); const old = st("1000", "1.5", ""); followPipeHeights(old, "800", "1000"); writeFileSync(process.argv[2], JSON.stringify({ fresh, noPipe, read, small, change, old })); """ @pytest.mark.skipif(not TSC.is_file(), reason="프론트엔드 의존성 미설치") def test_화면_높이_규칙(tmp_path: Path) -> None: out = tmp_path / "js" subprocess.run( # noqa: S603 — 고정 실행 파일 [ "node", str(TSC), str(ROOT / "common_util" / "common_util_culvert_sets.ts"), "--outDir", str(out), "--module", "esnext", "--target", "es2022", "--skipLibCheck", "--ignoreConfig", ], cwd=str(ROOT), capture_output=True, ) (out / "runner.mjs").write_text(_RUNNER, encoding="utf-8") result = tmp_path / "out.json" run = subprocess.run( # noqa: S603 ["node", str(out / "runner.mjs"), str(result)], capture_output=True, text=True ) assert run.returncode == 0, run.stderr[-2000:] got = json.loads(result.read_text(encoding="utf-8")) for key in ("outlet_revet_height_m", "inlet_basin_height_m"): assert got["fresh"][key] == pytest.approx(1.7), key # Φ1200 → 1.7 assert got["fresh"]["inlet_revet_height_m"] == pytest.approx(1.9) # 유입 흙막이 + 0.7(211-1) assert "inlet_revet_height_m" not in got["noPipe"] # 관경 없음 = 안 채움 assert got["read"]["inlet"][0]["height"] == "1.7" # 옛 1.5 · Φ1200 → 1.7 assert got["read"]["outlet"][0]["height"] == "1.6" # 손 값 그대로 assert got["small"]["inlet"][0]["height"] == "1.5" # Φ800 의 1.5 는 그대로 assert ( got["change"]["inlet"][0]["height"] == "2.2" ) # 옛 + 0.5 값(1.7) → 유입 새 규칙(1.5 + 0.7) assert got["change"]["outlet"][0]["height"] == "2.2" # 손 값 그대로 assert got["old"]["inlet"][0]["height"] == "1.5" # 옛 1.5 → Φ800 유입 규칙(0.8 + 0.7) assert got["old"]["outlet"][0]["height"] == "" # 빈 칸 그대로