- 새 칸 design.structure_note_cad — 스키마 · 재계산 남김 · 세션 초안 structure-note-cads · [저장] patch - 상세 모달 글 상자 → 빈 CAD(cad_host bare · 높이 고정 · 닫으면 destroy · 고칠 때마다 초안) - 처음 열 때 칸이 없으면 옛 글 줄마다 Text · 없으면 횡단배수 주인 측점만 미리 넣음 - 시험 test_260_note_cad · helper_260_note_cad Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TNMXVCZXMpHpVvqmFkeChL
158 lines
6.9 KiB
Python
158 lines
6.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""PLAN 260 — B06 [상세] 표 위 CAD 칸(`structure_note_cad`) → B07 횡단도 표 위.
|
|
|
|
- 260-1 칸: 스키마 · 재계산 남김 · 세션 초안 → [저장] patch.
|
|
- 260-2 미리 넣음: 횡단배수 주인 측점만 · 관 · 유입 · 유출 · 도수로 · 빈 구조물 · 옛 글 옮김
|
|
(`helper_260_note_cad.cjs` 가 실제 TS 를 Node 로 돌림).
|
|
|
|
./venv/Scripts/python.exe -m pytest resources/tester/test_260_note_cad.py -q
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
|
if str(PROJECT_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
|
|
from B06_Section import B06_Section_Router_Design as design_mod # noqa: E402
|
|
from B06_Section.B06_Section_Schema import CrossSectionPatch # noqa: E402
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
TEXT = {
|
|
"id": "t1",
|
|
"type": "Text",
|
|
"lineColor": "#ff7f7f",
|
|
"lineWidth": 1,
|
|
"layerId": "기본",
|
|
"shapeData": {"label": "NO.71+13", "basePoint": {"x": 15, "y": -1.5}, "options": {}},
|
|
}
|
|
CAD = {"entities": [TEXT], "layers": [{"id": "기본", "name": "기본"}]}
|
|
|
|
# ── 260-1 칸 ────────────────────────────────────────────────────────────
|
|
|
|
|
|
def test_CAD_칸은_patch_스키마를_지나_그대로_남는다():
|
|
dumped = CrossSectionPatch(chainage_m=40.0, structure_note_cad=CAD).model_dump()
|
|
merged = {k: v for k, v in dumped.items() if k != "chainage_m" and v is not None}
|
|
assert merged == {"structure_note_cad": CAD}
|
|
# 빈 엔티티 = 비움 — 걸러지지 않고 실림(옛 글 대신 아무것도 안 놓음)
|
|
empty = CrossSectionPatch(chainage_m=40.0, structure_note_cad={"entities": []}).model_dump()
|
|
assert empty["structure_note_cad"] == {"entities": [], "layers": None}
|
|
# 안 보냄 = 안 바꿈
|
|
assert CrossSectionPatch(chainage_m=40.0).model_dump()["structure_note_cad"] is None
|
|
|
|
|
|
def test_CAD_칸은_엔티티_수_상한():
|
|
with pytest.raises(ValueError):
|
|
CrossSectionPatch(chainage_m=40.0, structure_note_cad={"entities": [TEXT] * 2001})
|
|
|
|
|
|
def test_CAD_칸은_재계산에서도_남는다(monkeypatch):
|
|
assert "structure_note_cad" in design_mod.USER_TOUCHED_KEYS
|
|
monkeypatch.setattr(design_mod, "pavement_ranges", lambda root: [(0.0, 100.0)])
|
|
monkeypatch.setattr(design_mod, "ford_surface_drops", lambda root: [])
|
|
monkeypatch.setattr(design_mod, "design_elevation_from_longitudinal", lambda lon, ch: 100.0)
|
|
monkeypatch.setattr(design_mod, "curve_widening_args", lambda section: {})
|
|
monkeypatch.setattr(
|
|
design_mod, "compute_cross_design", lambda samples, elev, **kw: {"paved": kw["paved"]}
|
|
)
|
|
sections = [{"chainage_m": 40.0, "design": {"paved": False, "structure_note_cad": CAD}}]
|
|
assert design_mod.enforce_pavement_ranges({}, sections, Path("."), None) == 1
|
|
assert sections[0]["design"]["structure_note_cad"] == CAD
|
|
|
|
|
|
def test_브라우저가_CAD_칸을_저장_patch_에_싣는다():
|
|
read = lambda rel: (PROJECT_ROOT / rel).read_text(encoding="utf-8") # noqa: E731
|
|
persist = read("B06_Section/B06_Section_UI_Page_Persist.ts")
|
|
assert "readStructureNoteCads(" in persist and ".structure_note_cad = cad" in persist
|
|
state = read("A00_Common/b_page_state.ts")
|
|
assert '"structure-note-cads": { bucket: "draft", scope: "route" }' in state
|
|
# 캐시 설계 → B05 [저장] 길(`crossPatchesFromCache`)도 같은 목록
|
|
assert '"structure_note_cad",' in read("B06_Section/B06_Section_Cross_Refresh.ts")
|
|
# 모달 = 빈 CAD(캔버스만) · 글 상자 없음
|
|
detail = read("B06_Section/B06_Section_UI_Cross_Detail.ts")
|
|
assert "textarea" not in detail and "mountNoteCad(" in detail and "noteCad?.destroy()" in detail
|
|
assert "bare: true" in read("B06_Section/B06_Section_UI_Cross_Detail_Cad.ts")
|
|
|
|
|
|
# ── 260-2 미리 넣음 ─────────────────────────────────────────────────────
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def out() -> dict:
|
|
proc = subprocess.run( # noqa: S603 — 고정 실행 파일
|
|
["node", str(HERE / "helper_260_note_cad.cjs")],
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
timeout=60,
|
|
)
|
|
assert proc.returncode == 0, proc.stderr
|
|
return json.loads(proc.stdout)
|
|
|
|
|
|
def _labels(entities: list[dict]) -> list[str]:
|
|
return [entity["label"] for entity in entities if entity["type"] == "Text"]
|
|
|
|
|
|
def test_관_유입_유출_도수로_한_벌(out):
|
|
"""그림(162-21) 꼴 — 원 안 세 줄 · 오른쪽 측점 · 관보호공 둘 · 관유출부보강."""
|
|
full = out["full"]
|
|
assert [entity["type"] for entity in full[:2]] == ["Circle", "Line"]
|
|
assert _labels(full) == [
|
|
"배수관",
|
|
"Φ1200m/m",
|
|
"L=22.0m",
|
|
"NO.71+13",
|
|
"관보호공(유입) 기슭막이(찰,H=2.0) L=10.0m",
|
|
"관보호공(유출) 기슭막이(메,H=2.0) L=10.0m",
|
|
"관유출부보강(돌붙임,찰) 10m2",
|
|
]
|
|
# 원 안 = 가운데 맞춤 · 원 중심 x · 오른쪽 = 왼쪽 맞춤 · 줄 3.0 간격 · 붉은 계열 · 기본 층
|
|
inside, right = full[2:5], full[5:]
|
|
assert {(e["align"], e["x"]) for e in inside} == {("center", full[0]["x"])}
|
|
assert [e["y"] for e in right] == [-1.5, -4.5, -7.5, -10.5]
|
|
assert {e["align"] for e in right} == {"left"}
|
|
assert {e["color"] for e in full} == {"#ff7f7f"} and {e["layer"] for e in full} == {"기본"}
|
|
|
|
|
|
def test_관_길이_없으면_L_뒤_빈칸(out):
|
|
assert _labels(out["noLength"])[2] == "L="
|
|
# 도수로 상자가 없으면 관유출부보강 줄 없음
|
|
assert not any(label.startswith("관유출부보강") for label in _labels(out["noLength"]))
|
|
|
|
|
|
def test_유입_집수정_은_형태_높이_길이(out):
|
|
assert "관보호공(유입) 집수정(L형,H=1.7) L=2.0m" in _labels(out["basin"])
|
|
|
|
|
|
def test_도수로_옵션이_없으면_세트_구조만(out):
|
|
assert _labels(out["chuteFallback"])[-1] == "관유출부보강(도수로) m2"
|
|
|
|
|
|
def test_보호공을_안_고르면_관과_측점만(out):
|
|
assert _labels(out["noSides"]) == ["배수관", "Φ1200m/m", "L=22.0m", "NO.71+13"]
|
|
|
|
|
|
@pytest.mark.parametrize("case", ["none", "ford", "hidden", "neighbour"])
|
|
def test_횡단배수_주인_측점이_아니면_빈값(out, case):
|
|
"""구조물 없음 · 상자형(세월교 · 박스) · 숨은 관(독립 기슭막이) · 이웃 측점 = 빈 도면."""
|
|
assert out[case] == []
|
|
|
|
|
|
def test_옛_글은_줄마다_Text_로_옮김(out):
|
|
legacy = out["legacy"]
|
|
assert _labels(legacy) == ["L형 측구", "집수정 보강"]
|
|
# 빈 줄은 자리만 — B07 옛 글 줄과 같은 높이(줄 3.0 · 가운데)
|
|
assert [e["y"] for e in legacy] == [-1.5, -7.5] and {e["x"] for e in legacy} == {0}
|
|
assert out["legacyEmpty"] == 0
|
|
|
|
|
|
def test_측점_이름은_B07_꼴(out):
|
|
assert out["station"] == ["NO.71+13", "NO.71", "NO.72"]
|