- 기본 종류 = 지형도 하나(옛 기본 이관 더하기 지움) · 대피소 조각 · 자리 폼 · plan-marks 끝점 지움 - 모달 양식 칸 = 평면도면 숨김 · 종류 척도 영역 2열 · 항목 3열 유지 + 그룹 구분선(PIECE_GROUPS 한 곳) - 낡은 시험 수선: 기본 종류가 하나로 줄어 route · layout · landuse · watershed 기본 전제를 add_kind 로 세움 · 대피소 자리 시험 지움 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
109 lines
4.6 KiB
Python
109 lines
4.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""512-1 B07 유역도 등고선 간격 5 m 기본 · 종류 옵션 10 m(임시 폴더 · DB · 실제 마스터 안 씀).
|
|
|
|
- 배경선 = 간격 배수 높이만(높이 없는 선은 남김 · None = 전부)
|
|
- 유역도 종류 = contour_interval_m 5 기본 · 10 고름 · 1 거절 · 평면도 양식엔 칸 없음
|
|
- 지문 = 간격 바꾸면 유역도만 · 기본 종류를 파일로 내려도 그대로 · 같은 값 = 같은 지문
|
|
|
|
./venv/Scripts/python.exe -m pytest resources/tester/test_512_1_b07_basin_contour.py -q
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from B07_DesignDetail import B07_DesignDetail_Router_Support_Fingerprint as fp # noqa: E402
|
|
from B07_DesignDetail.B07_DesignDetail_Router_Support_Basin import _metric_lines # noqa: E402
|
|
from B07_DesignDetail.B07_DesignDetail_Router_Support_Plan import ( # noqa: E402
|
|
_kinds_dir,
|
|
list_kinds,
|
|
update_kind,
|
|
)
|
|
|
|
|
|
def _line(level: float | None, x: float) -> dict:
|
|
props = {} if level is None else {"등고수치": level}
|
|
coords = [[x, 0.0], [x, 1.0]]
|
|
return {"properties": props, "geometry": {"type": "LineString", "coordinates": coords}}
|
|
|
|
|
|
def test_간격_배수_높이만(tmp_path):
|
|
path = tmp_path / "contour.geojson"
|
|
features = [_line(775.0, 0), _line(780.0, 1), _line(785.0, 2), _line(None, 3)]
|
|
path.write_text(json.dumps({"type": "FeatureCollection", "features": features}), "utf-8")
|
|
xs = lambda lines: [line[0][0] for line in lines] # noqa: E731
|
|
assert xs(_metric_lines(path, "EPSG:4326")) == [0, 1, 2, 3]
|
|
assert xs(_metric_lines(path, "EPSG:4326", None, 5)) == [0, 1, 2, 3]
|
|
assert xs(_metric_lines(path, "EPSG:4326", None, 10)) == [1, 3]
|
|
assert xs(_metric_lines(path, "EPSG:4326", (-1, -1, 1.5, 2), 10)) == [1]
|
|
|
|
|
|
def _watershed(root: Path) -> dict:
|
|
folder = _kinds_dir(root)
|
|
if not folder.is_dir(): # 기본 종류는 지형도뿐(524-1) — 유역도 종류를 파일로 둠
|
|
folder.mkdir(parents=True)
|
|
for order, (name, layout) in enumerate((("지형도", "plan"), ("배수유역도", "watershed"))):
|
|
document = {"name": name, "pieces": ["contour"], "order": order, "layout": layout}
|
|
(folder / f"{'terrain' if layout == 'plan' else 'watershed'}.json").write_text(
|
|
json.dumps(document), "utf-8"
|
|
)
|
|
return next(kind for kind in list_kinds(root) if kind["layout"] == "watershed")
|
|
|
|
|
|
def test_유역도_종류_간격(tmp_path):
|
|
root = tmp_path / "proj"
|
|
assert _watershed(root)["contour_interval_m"] == 5
|
|
assert all("contour_interval_m" not in k for k in list_kinds(root) if k["layout"] == "plan")
|
|
kind = _watershed(root)
|
|
update_kind(root, kind["id"], kind["name"], [], None, 10)
|
|
assert _watershed(root)["contour_interval_m"] == 10
|
|
update_kind(root, kind["id"], kind["name"], []) # 간격 안 보냄 = 지금 값
|
|
assert _watershed(root)["contour_interval_m"] == 10
|
|
with pytest.raises(ValueError):
|
|
update_kind(root, kind["id"], kind["name"], [], None, 1)
|
|
|
|
|
|
def test_지문_유역도만(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(fp, "detail_basins_path", lambda stored: tmp_path / "basins.geojson")
|
|
root = tmp_path / "proj"
|
|
longitudinal = root / "B06_Section" / "longitudinal" / "longitudinal.json"
|
|
longitudinal.parent.mkdir(parents=True)
|
|
longitudinal.write_text(json.dumps({"stations": [{"chainage_m": 0}]}), encoding="utf-8")
|
|
context = SimpleNamespace(
|
|
vertices=[SimpleNamespace(x=0.0, y=0.0), SimpleNamespace(x=10.0, y=0.0)],
|
|
crs="EPSG:5186",
|
|
surface_params={},
|
|
stored_path="x",
|
|
)
|
|
items = [
|
|
SimpleNamespace(id="cover", kind="cover"),
|
|
SimpleNamespace(id="plan_route", kind="plan"),
|
|
SimpleNamespace(id="plan_watershed", kind="plan"),
|
|
]
|
|
sources = {"title": {}, "designs": {}, "context": context}
|
|
|
|
def prints() -> dict:
|
|
found = fp.compute_fingerprints(root, longitudinal, items, sources)
|
|
return {key: value["fingerprint"] for key, value in found.items()}
|
|
|
|
def changed(before: dict, after: dict) -> set:
|
|
return {key for key in before if before[key] != after[key]}
|
|
|
|
kind = _watershed(root)
|
|
first = prints()
|
|
update_kind(root, kind["id"], kind["name"], [], None, 5) # 같은 값
|
|
assert changed(first, prints()) == set()
|
|
update_kind(root, kind["id"], kind["name"], [], None, 10)
|
|
ten = prints()
|
|
assert changed(first, ten) == {"plan_watershed"}
|
|
update_kind(root, kind["id"], kind["name"], [], None, 5)
|
|
assert prints() == first
|