- 전수 표 시험 test_322_0_golden + helper_322_0_golden.cjs · 기록 golden_322_structures.json(측점 · 카드 이름 · 형상 열쇠 · 3D 몸체 · 알약 띠 · 고르기 목록 · 물빼기 · ★ 27칸) - 이관 = 지금 판 + 구조물정의_이력 판_N 종류 이름 측점은 안 옮김(all_type_names) - GET /api/m02/structure-definition/version · dropStaleStructureTypes · onStaleStructureTypes - _registry_defaults lru 걷음(정의 읽기가 이미 파일 시각 캐시) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
74 lines
3.1 KiB
Python
74 lines
3.1 KiB
Python
"""PLAN 322-0 ② — 「기타」 유령 길 막기: 종류 이름을 바꾼 뒤에도 옛 이름 측점을 구조물로 되옮기지 않음.
|
|
|
|
정의 사본(임시 폴더 · 마스터 안 고침)에서 종류 이름을 바꾸고 앞 판을 `구조물정의_이력/판_N.json` 으로 둠 →
|
|
옛 이름 · 새 이름 측점 모두 이관 0건. 옛 꼴 자유 글(기성막이 · 대피로 폭 · 임의 이름)은 종전대로 옮김.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from B05_Profile import B05_Profile_Structures_Schema as schema
|
|
from B05_Profile.B05_Profile_Structures_Migration import migrate_irregular_stations
|
|
|
|
MASTER = Path(schema.DEFINITION_PATH)
|
|
RENAMED = {
|
|
"cross_drain_exposed": "노출수로",
|
|
"box_culvert": "박스암거",
|
|
"retaining_wall": "옹벽(신)",
|
|
}
|
|
|
|
|
|
@pytest.fixture()
|
|
def renamed(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> dict:
|
|
old = json.loads(MASTER.read_text(encoding="utf-8"))
|
|
history = tmp_path / schema.HISTORY_DIRNAME
|
|
history.mkdir()
|
|
shutil.copy(MASTER, history / f"판_{old['판']}.json")
|
|
new = {**old, "판": old["판"] + 1}
|
|
new["types"] = [{**t, "name": RENAMED.get(t["type_id"], t["name"])} for t in old["types"]]
|
|
path = tmp_path / "구조물정의.json"
|
|
path.write_text(json.dumps(new, ensure_ascii=False), encoding="utf-8")
|
|
monkeypatch.setattr(schema, "DEFINITION_PATH", str(path))
|
|
return old
|
|
|
|
|
|
def _moved(label: str) -> int:
|
|
plan = migrate_irregular_stations([{"chainage_m": 120.0, "structure": label}])
|
|
return len(plan.structures) + len(plan.pipe_facilities)
|
|
|
|
|
|
def test_old_and_new_names_are_not_migrated(renamed: dict) -> None:
|
|
assert schema.structure_type_map()["box_culvert"].name == "박스암거" # 사본을 읽음
|
|
for type_id, name in RENAMED.items():
|
|
old_name = next(t["name"] for t in renamed["types"] if t["type_id"] == type_id)
|
|
assert _moved(old_name) == 0, old_name
|
|
assert _moved(name) == 0, name
|
|
|
|
|
|
def test_every_type_name_of_any_version_is_blocked(renamed: dict) -> None:
|
|
names = {t["name"] for t in renamed["types"]} | set(RENAMED.values())
|
|
assert names <= schema.all_type_names()
|
|
assert [name for name in sorted(names) if _moved(name)] == []
|
|
|
|
|
|
def test_legacy_free_text_still_migrates(renamed: dict) -> None:
|
|
assert _moved("기성막이") == 1 # 옛 오기 → 기슭막이(관 지점)
|
|
plan = migrate_irregular_stations([{"chainage_m": 300.0, "structure": "대피로 2.0m"}])
|
|
assert [s.type_id for s in plan.structures] == ["refuge"]
|
|
plan = migrate_irregular_stations([{"chainage_m": 15.0, "structure": "돌망태 보강"}])
|
|
assert [(s.type_id, s.options["name"]) for s in plan.structures] == [("etc", "돌망태 보강")]
|
|
|
|
|
|
def test_master_history_names_are_read() -> None:
|
|
"""실제 마스터 이력(판_1 ~)의 이름도 모음 — 이력 파일은 읽기만."""
|
|
history = MASTER.parent / schema.HISTORY_DIRNAME
|
|
names = set()
|
|
for path in history.glob("판_*.json"):
|
|
names |= {t["name"] for t in json.loads(path.read_text(encoding="utf-8"))["types"]}
|
|
assert names <= schema.all_type_names()
|