"""54-4 — 저장으로 관 지점 종류만 바꾸면 횡단 측점 라벨(카드 제목)이 새 종류를 따라감. 측점은 다시 안 만들어지므로 라벨은 파일에 옛 종류로 남음 — 상세 조회가 지금 관 지점으로 고침. 다른 구조물 라벨(옹벽 등)은 건드리지 않음. """ import json from B05_Profile.B05_Profile_Engine_Sections import relabel_pipe_stations, resolve_extra_stations from common_util.common_util_drainage_pipes import parse_pipe_points def _write_points(root, points): edits = root / "B04_PreProcess" / "drainage" / "edits" edits.mkdir(parents=True, exist_ok=True) (edits / "pipe_points.json").write_text(json.dumps({"points": points}), encoding="utf-8") def _sections(): return [ {"chainage_m": 80.0}, {"chainage_m": 85.05, "structure": "파형강관 D900"}, {"chainage_m": 120.0, "structure": "옹벽"}, {"chainage_m": 173.09, "structure": "세월교"}, {"chainage_m": 258.12, "structure": "파형강관 D800"}, ] def test_relabel_follows_saved_kind(tmp_path): _write_points( tmp_path, [ {"chainage_m": 85.05, "source": "spacing", "facility": "box_culvert"}, {"chainage_m": 120.0, "source": "user", "facility": "box_culvert"}, # 옹벽 라벨 자리 { "chainage_m": 173.09, "source": "stream", "facility": "pipe", "options": {"pipe_kind": "흄관", "pipe_diameter_mm": 1200}, }, {"chainage_m": 258.12, "source": "spacing", "facility": "ford_pavement"}, ], ) sections = _sections() relabel_pipe_stations(tmp_path, sections) labels = {s["chainage_m"]: s.get("structure") for s in sections} assert labels == { 80.0: None, 85.05: "BOX암거", 120.0: "옹벽", # 관 지점 라벨이 아닌 측점은 그대로 173.09: "흄관 D1200", 258.12: None, # 물넘이포장 = 라벨 없음(측점 생성 규칙과 같음) } def test_relabel_matches_generation_rule(tmp_path): points = [ {"chainage_m": 85.05, "source": "spacing", "options": {"pipe_diameter_mm": 1000}}, {"chainage_m": 173.09, "source": "stream", "facility": "ford_bridge"}, ] _write_points(tmp_path, points) sections = [ {"chainage_m": 85.05, "structure": "세월교"}, {"chainage_m": 173.09, "structure": "BOX암거"}, ] relabel_pipe_stations(tmp_path, sections) generated = dict(resolve_extra_stations(tmp_path, parse_pipe_points(points))) assert [s["structure"] for s in sections] == [generated[85.05], generated[173.09]] def test_relabel_without_file_keeps_labels(tmp_path): sections = _sections() relabel_pipe_stations(tmp_path, sections) assert sections == _sections()