Files
Aislo/resources/tester/test_273_2_preview_stations.py
T
eomsangdonandClaude Opus 5.5 d9fec937aa fix(B05·B06 한 페이지): 시설 옮김 = 횡단 편집 열쇠째 · [저장] 중 먹이기 멈춤 · 새 시설 측점 미리보기 걷음 · 되돌리기 뒤 다시 견줌 (415-1 · 415-2)
- H1: 관 · 구조물 밖 측점이 움직인 때만 「노선 바뀜」 넘김 규칙 · 시설만 옮기면 열쇠째 옮김
  (사면 쉬프트 · 소단 깊이 · 단면 유형 · 관 측점 고침 그대로)
- H1 덧: 초안 없을 때도 저장분 계획으로 열쇠 주인(관 = 저장 id · 계산 묶음 열쇠와 같음 · 첫 옮김도 열쇠째)
  · 묶음이 세운 열쇠 목록을 같은 측점이면 주인 규칙으로 다시 세지 않음 · 갈아끼운 옛 상세 맞춤 끝냄
- H2: [저장] 도중 관 · 구조물 먹이기 · 맞춤 고리 쉼 · 끝나면 저장 목록 다시 읽고 맞춤(design_pipeline_facilities)
- M4: 새 시설 측점 서버 미리보기(preview-stations) 걷음 · 새 자리 = 계산 묶음 갈아끼움 · 카드 이름만 얹음
  · 종류 바뀐 자리 = 구조물 없는 사본
- 415-2: 되돌리기 · 다시하기(세션만 되씀) 뒤 관 · 구조물을 묶음 입력과 견줘 다시 넣음
- 시험: test_415_page_split 새로 · 미리보기 전제 시험(273-2 · 298 · 317 · 318 · 322-0 · 322-3)을 새 규칙으로

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TteK8mfYZetk5P3bEZkyVZ
2026-10-18 13:14:59 +09:00

132 lines
5.2 KiB
Python

"""273-2 B06 횡단도 바로 반영 — 초안 자리 횡단 미리 뜨기(요구 168).
- 미리 뜨기(`sample_structure_sections`)는 파일을 안 쓰고, [저장] 때 정본 쓰기
(`generate_irregular_sections`)와 같은 횡단을 낸다(같은 길 · 화면이 본 값 = 저장 값).
- 기본 설계(`compute_default_designs`)는 파일 대신 받은 횡단으로도 셈.
- 화면 쪽: 옛 자리 숨김 · 새 자리는 안 물음(415 M4 · 계산 묶음 갈아끼움이 얹음) · 관 그림 · 늦게 끝난 옛
맞춤이 새 것을 안 덮음(`helper_273_2_preview_stations.cjs`).
"""
from __future__ import annotations
import json
import subprocess
from pathlib import Path
import numpy as np
import pytest
import B05_Profile.B05_Profile_Engine_Sections as sections
from B06_Section.B06_Section_Router_Design import compute_default_designs
from common_util.common_util_drainage_pipes import route_signature
from common_util.common_util_route_geometry import RouteVertex
HERE = Path(__file__).resolve().parent
ROOT = HERE.parents[1]
LINE = [[0.0, 0.0, 100.0], [350.0, 0.0, 100.0]]
ROUTE = "B05_Profile/route/route.geojson"
class _Slope:
"""옆으로 기운 지표 — 왼쪽이 높음(상단측 = left)."""
def sample_xy(self, xy):
points = np.asarray(xy, dtype=np.float64).reshape(-1, 2)
return 100.0 + 0.2 * points[:, 1], np.ones(len(points), dtype=bool)
def _write(root: Path, rel: str, data) -> None:
path = root / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
def _project(root: Path) -> None:
_write(root, ROUTE, {"geometry": {"type": "LineString", "coordinates": LINE}})
vertices = [RouteVertex(x=p[0], y=p[1], z=p[2], chainage_m=0.0) for p in LINE]
_write(
root,
"B04_PreProcess/drainage/edits/pipe_points.json",
{"route_signature": route_signature(vertices), "points": []},
)
def _files(root: Path) -> list[str]:
return sorted(str(p.relative_to(root)) for p in root.rglob("*") if p.is_file())
def test_미리_뜨기는_안_쓰고_저장과_같은_횡단(tmp_path: Path, monkeypatch) -> None:
_project(tmp_path)
monkeypatch.setattr(sections, "build_surface_sampler", lambda *_a, **_k: _Slope())
before = _files(tmp_path)
stations, crosses = sections.sample_structure_sections(
tmp_path, ROUTE, "csf", "tin", False, extra_stations=((130.0, ""),)
)
assert _files(tmp_path) == before # 파일 · 폴더 하나도 안 생김
assert [c["chainage_m"] for c in crosses] == [130.0] and len(stations) == 1
sections.generate_irregular_sections(
tmp_path, ROUTE, "csf", "tin", False, extra_stations=((130.0, "파형강관 D800"),)
)
written = json.loads(
(tmp_path / "B06_Section/cross_sections/cross_00130m.json").read_text(encoding="utf-8")
)
assert written["samples"] == crosses[0]["samples"]
assert written["frame"] == crosses[0]["frame"]
def test_기본_설계는_받은_횡단으로도_셈(tmp_path: Path) -> None:
rel = "B06_Section/longitudinal/longitudinal.json"
plan = [{"chainage_m": c, "elevation_m": 851.0} for c in (0.0, 1000.0)]
_write(tmp_path, rel, {"stations": [], "design_profiles": [{"samples": plan}]})
offsets = np.arange(-20.0, 20.5, 0.5)
cross = {
"chainage_m": 610.0,
"uphill_side": "right",
"samples": [
{"offset_m": float(o), "elevation_m": 852.0 - 0.1 * float(o), "valid": True}
for o in offsets
],
}
designs = compute_default_designs(tmp_path, rel, [610.0], crosses={610.0: cross})
assert [chainage for chainage, _ in designs] == [610.0]
design = designs[0][1]
assert design["status"] == "provisional" and design.get("section_mode")
# 파일에도 없고 받은 횡단에도 없는 자리는 건너뜀
assert compute_default_designs(tmp_path, rel, [611.0], crosses={610.0: cross}) == []
@pytest.fixture(scope="module")
def ts() -> dict:
if not (ROOT / "config" / "node_modules" / "typescript").is_dir():
pytest.skip("프론트엔드 의존성 미설치")
proc = subprocess.run( # noqa: S603 — 고정 실행 파일
["node", str(HERE / "helper_273_2_preview_stations.cjs")],
capture_output=True,
text=True,
encoding="utf-8",
cwd=str(ROOT),
check=False,
)
assert proc.returncode == 0, proc.stderr
return json.loads(proc.stdout)
def test_화면_옛_자리_숨기고_새_자리_안_물음(ts) -> None:
# 415 M4 — 새 자리 서버 미리보기 걷음(브라우저 계산 줄 하나) · 옛 95.38 숨김 · 미리보기 요청 0
assert ts["moved"]["chainages"] == [0, 20, 40, 100]
assert ts["moved"]["asked"] == []
def test_묶음이_얹은_새_자리는_그대로_관_그림(ts) -> None:
assert ts["again"]["asked"] == []
assert ts["again"]["chainages"] == [0, 20, 40, 95, 100]
assert ts["again"]["swapped"] == {"preview": False, "culvert": True}
def test_초안이_없으면_서버_목록_그대로(ts) -> None:
assert ts["cleared"]["chainages"] == [0, 20, 40, 95, 95.38, 100]
def test_늦게_끝난_옛_맞춤이_새_것을_안_덮음(ts) -> None:
assert ts["race"]["chainages"] == [0, 20, 40, 100]