Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XWh5wNNycMkbwMpACz1rte
155 lines
6.5 KiB
Python
155 lines
6.5 KiB
Python
"""PLAN 376-1 B07 구조물 도면 — 조합마다 한 장 · 더한장 장마다 · 맨 뒤(도면번호 안 밀림) ·
|
|
도각(도번 · 도면명) · 확정본 kind.
|
|
|
|
임시 폴더 견본만 씀 — 연결된 사본(`linked_snapshots`) · 사본 폴더는 바꿔 끼움.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from B07_DesignDetail import B07_DesignDetail_Router as router
|
|
from B07_DesignDetail import B07_DesignDetail_Router_Support as support
|
|
from B07_DesignDetail import B07_DesignDetail_Router_Support_Structure as structure
|
|
from B07_DesignDetail.B07_DesignDetail_Engine_Cad import DRAWING_FORMAT
|
|
from B07_DesignDetail.B07_DesignDetail_Engine_Template import (
|
|
use_project_templates,
|
|
use_title_fields,
|
|
)
|
|
from B07_DesignDetail.B07_DesignDetail_Router_Support_Io import _design_root, _write_manifest
|
|
|
|
ITEM_A = {"layer": "system", "owner": None, "key": "SS000002", "name": "관보호공 조합"}
|
|
ITEM_B = {"layer": "company", "owner": "3", "key": "SC3-000001", "name": "BOX 조합"}
|
|
KEY_A = "system_none_SS000002"
|
|
KEY_B = "company_3_SC3-000001"
|
|
|
|
|
|
def _sheet(tag: str) -> dict:
|
|
text = {
|
|
"id": f"t-{tag}",
|
|
"type": "Text",
|
|
"lineColor": "#ffffff",
|
|
"lineWidth": 1,
|
|
"layerId": "기본",
|
|
"shapeData": {"basePoint": {"x": 300, "y": 300}, "label": tag, "options": {}},
|
|
}
|
|
return {"format": "openwebcad", "entities": [text], "layers": [{"id": "기본"}]}
|
|
|
|
|
|
@pytest.fixture
|
|
def project(tmp_path: Path, monkeypatch) -> Path:
|
|
"""조합 둘 — A 를 배치 둘이 씀(관 · 구조물) · A 에 더한장 하나 · B 는 도번 앞섬."""
|
|
from M02_MasterTemplete import M02_Item_Snapshot as snapshot
|
|
|
|
base = tmp_path / "structures"
|
|
docs = {
|
|
"pipe@10__grv6lny": {
|
|
"도번": "SD-000002",
|
|
"도면": _sheet("A1"),
|
|
"더한장": [{"장id": "s9x", "이름": "상세", "도면": _sheet("A2")}],
|
|
},
|
|
"box1": {"도번": "SD-000002", "도면": _sheet("A-다른배치")},
|
|
"box2": {"도번": "SD-000001", "도면": _sheet("B1")},
|
|
}
|
|
items = {"pipe@10__grv6lny": ITEM_A, "box1": ITEM_A, "box2": ITEM_B}
|
|
linked = {}
|
|
for owner, doc in docs.items():
|
|
folder = owner.replace("@", "_")
|
|
(base / folder).mkdir(parents=True)
|
|
(base / folder / "도면.json").write_text(json.dumps(doc, ensure_ascii=False), "utf-8")
|
|
linked[owner] = {"항목": items[owner], "폴더": folder, "부분": ["도면"], "경로": []}
|
|
linked["noshape"] = {"항목": ITEM_B, "폴더": "none", "부분": ["면적"], "경로": []}
|
|
monkeypatch.setattr(snapshot, "linked_snapshots", lambda root: linked)
|
|
monkeypatch.setattr(snapshot, "structures_dir", lambda root: base)
|
|
|
|
# 노선 자료 쪽은 고정 — 종단 한 장 · 표지 등 단장만
|
|
monkeypatch.setattr(
|
|
support, "longitudinal_chunks", lambda _l: [{"id": "longitudinal", "label": "종단도"}]
|
|
)
|
|
monkeypatch.setattr(support, "_cross_sheet_plan", lambda *_: [])
|
|
monkeypatch.setattr(support, "plan_kind_items", lambda *_: [])
|
|
(tmp_path / "longitudinal.json").write_text(json.dumps({"stations": []}), "utf-8")
|
|
use_project_templates(None)
|
|
use_title_fields({})
|
|
return tmp_path
|
|
|
|
|
|
def _list(root: Path):
|
|
return support._drawing_list(root, root / "longitudinal.json")
|
|
|
|
|
|
def test_조합마다_한장_더한장은_장마다_맨뒤(project: Path) -> None:
|
|
drawings = _list(project)
|
|
ids = [d.id for d in drawings]
|
|
assert ids[:4] == ["longitudinal", "cover", "cross_standard", "mass_haul"]
|
|
structure = [d for d in drawings if d.kind == "structure"]
|
|
# 도번 차례(B SD-000001 먼저) · 같은 조합 A 두 배치 = 한 장 + 더한장
|
|
assert [d.id for d in structure] == [
|
|
f"structure_{KEY_B}",
|
|
f"structure_{KEY_A}",
|
|
f"structure_{KEY_A}_s9x",
|
|
]
|
|
assert [d.label for d in structure] == ["BOX 조합", "관보호공 조합", "관보호공 조합 · 상세"]
|
|
assert ids[4:] == [d.id for d in structure]
|
|
|
|
|
|
def test_도면번호_앞도면_안밀림(project: Path) -> None:
|
|
_list(project)
|
|
manifest = support._read_manifest(project)["drawings"]
|
|
assert manifest["longitudinal"]["number"] == 1
|
|
assert manifest["mass_haul"]["number"] == 4
|
|
assert manifest[f"structure_{KEY_B}"]["number"] == 5
|
|
assert manifest[f"structure_{KEY_A}_s9x"]["number"] == 7
|
|
|
|
|
|
def test_단건_도각_도번_도면명(project: Path) -> None:
|
|
_list(project)
|
|
kind, label, drawing, confirmed, table = support._read_drawing(
|
|
project, project / "longitudinal.json", f"structure_{KEY_A}_s9x"
|
|
)
|
|
assert (kind, label, confirmed, table) == ("structure", "관보호공 조합 · 상세", False, None)
|
|
texts = [e["shapeData"].get("label") for e in drawing["entities"] if e["type"] == "Text"]
|
|
assert "A2" in texts and "A1" not in texts # 그 장 그림만
|
|
assert "관보호공 조합 · 상세" in texts # 도면명
|
|
assert "SD-000002-2" in texts # 장 도번
|
|
assert any(layer.get("id") == "m02-structure-frame" for layer in drawing["layers"])
|
|
assert router._drawing_guide(drawing)["area"] # CAD 가이드 선 — 얹는 도각 층에서
|
|
|
|
|
|
def test_도각_층_이름_M02_와_같음() -> None:
|
|
from M02_MasterTemplete.M02_MasterTemplete_Router_Drawing import STRUCTURE_FRAME_LAYER
|
|
|
|
assert STRUCTURE_FRAME_LAYER == structure.STRUCTURE_FRAME_LAYER
|
|
|
|
|
|
def test_없는_구조물_도면은_404(project: Path) -> None:
|
|
with pytest.raises(FileNotFoundError):
|
|
support._read_drawing(project, project / "longitudinal.json", "structure_none_x")
|
|
|
|
|
|
def test_확정본_kind_structure(project: Path) -> None:
|
|
drawing_id = f"structure_{KEY_B}"
|
|
folder = _design_root(project) / "drawings"
|
|
folder.mkdir(parents=True, exist_ok=True)
|
|
saved = {"format": DRAWING_FORMAT, "entities": [], "layers": []}
|
|
(folder / f"{drawing_id}.json").write_text(json.dumps(saved), "utf-8")
|
|
_write_manifest(
|
|
project,
|
|
{"drawings": {drawing_id: {"confirmed": True, "label": "BOX 조합", "kind": "structure"}}},
|
|
)
|
|
kind, label, _drawing, confirmed, table = support._read_drawing(
|
|
project, project / "longitudinal.json", drawing_id
|
|
)
|
|
assert (kind, label, confirmed, table) == ("structure", "BOX 조합", True, None)
|
|
assert next(d for d in _list(project) if d.id == drawing_id).confirmed
|
|
|
|
|
|
def test_연결_없으면_빈목록(project: Path, monkeypatch) -> None:
|
|
from M02_MasterTemplete import M02_Item_Snapshot as snapshot
|
|
|
|
monkeypatch.setattr(snapshot, "linked_snapshots", lambda root: {})
|
|
assert [d for d in _list(project) if d.kind == "structure"] == []
|