- 재현(검증_sub4 B · 라이다 → 수치지형도 → [초기화]): stage 1 = 수치지형도 · 노선 행 = 라이다 모델 · 횡단 지반선 대 stage 1 지형 평균 3.78 m · 최대 13.67 m - 고친 뒤 같은 길(API · ORCA 칩 → [초기화]): 세 자리 라이다 · 어긋남 0 - las_selection · 등고선 간격 등 지형 밖 칸 안 건드림 · stage 1 행 없으면 안 씀 - 시험 test_637_4_reset_terrain 새로 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
"""PLAN 637-4 — 초기값에 설계 지형 고름을 담고 [초기화]가 함께 되돌림(요구 546).
|
|
|
|
지형 칩으로 설계 지형을 바꾼 뒤 [초기화] = 옛 지형으로 센 횡단 · 노선 행이 돌아오는데
|
|
stage 1 확정값 · CONFIRMED 모델은 새것 그대로였음. 가짜 커넥션으로 뜨기 · 되돌리기 규약만 봄.
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
import logging
|
|
|
|
from common_util.common_util_initial_snapshot import (
|
|
restore_initial_snapshot,
|
|
save_initial_snapshot,
|
|
snapshot_dir,
|
|
)
|
|
|
|
LAS = {"source_filter": "classification", "method": "dtm", "smooth": True}
|
|
STASH = {"source_filter": "classification", "method": "dtm", "smooth": True}
|
|
|
|
|
|
class _Cursor:
|
|
def __init__(self, db):
|
|
self.db = db
|
|
self.rows: list = []
|
|
self.rowcount = 0
|
|
self.lastrowid = 0
|
|
|
|
async def __aenter__(self):
|
|
return self
|
|
|
|
async def __aexit__(self, *_):
|
|
return False
|
|
|
|
async def execute(self, sql, params=None):
|
|
text = " ".join(sql.split())
|
|
head = text.split()[0].upper()
|
|
self.rows = []
|
|
if head == "INSERT":
|
|
self.db["next_id"] += 1
|
|
self.lastrowid = self.db["next_id"]
|
|
elif head == "UPDATE":
|
|
self.db["updates"].append((text, params))
|
|
if "project_workflow_stages" in text and "stage_no = 1" in text:
|
|
self.db["stage1"] = json.loads(params[0])
|
|
self.rowcount = 1
|
|
elif "FROM routes" in text:
|
|
self.rows = [{"id": 7, "project_id": "p1", "surface_model_id": 642}]
|
|
elif "stage_no = 1" in text:
|
|
self.rows = [{"params": json.dumps(self.db["stage1"])}]
|
|
|
|
async def fetchone(self):
|
|
return self.rows[0] if self.rows else None
|
|
|
|
async def fetchall(self):
|
|
return self.rows
|
|
|
|
|
|
class _Connection:
|
|
def __init__(self, db):
|
|
self.db = db
|
|
|
|
def cursor(self, *_args, **_kwargs):
|
|
return _Cursor(self.db)
|
|
|
|
|
|
def _db(stage1):
|
|
return {"stage1": dict(stage1), "updates": [], "next_id": 100}
|
|
|
|
|
|
def test_뜰_때_설계_지형_고름을_담음(tmp_path):
|
|
db = _db({**LAS, "contour_interval_m": 1.0, "input_file_id": "9"})
|
|
asyncio.run(save_initial_snapshot(_Connection(db), tmp_path, 7))
|
|
dump = json.loads((snapshot_dir(tmp_path) / "db.json").read_text(encoding="utf-8"))
|
|
assert dump["stage1_terrain"] == LAS
|
|
|
|
|
|
def _write_dump(root, **extra):
|
|
folder = snapshot_dir(root)
|
|
folder.mkdir(parents=True)
|
|
dump = {"routes": [{"id": 7, "project_id": "p1", "surface_model_id": 642}], **extra}
|
|
(folder / "db.json").write_text(json.dumps(dump), encoding="utf-8")
|
|
|
|
|
|
def test_초기화가_설계_지형과_확정_모델을_되돌림(tmp_path):
|
|
_write_dump(tmp_path, stage1_terrain=LAS)
|
|
# 칩으로 수치지형도로 바꾼 뒤 — 라이다 값은 las_selection 에 적혀 있음
|
|
sheet = {"source_filter": "sheet_laplace", "method": "dtm", "smooth": True}
|
|
db = _db({**sheet, "contour_interval_m": 2.0, "las_selection": STASH, "input_file_id": "9"})
|
|
new_id = asyncio.run(restore_initial_snapshot(_Connection(db), tmp_path, "p1"))
|
|
|
|
assert new_id == 101
|
|
assert {key: db["stage1"][key] for key in LAS} == LAS
|
|
# 지형 밖 칸 · 라이다 적어 둔 값은 그대로
|
|
assert db["stage1"]["contour_interval_m"] == 2.0
|
|
assert db["stage1"]["las_selection"] == STASH
|
|
assert db["stage1"]["input_file_id"] == "9"
|
|
# CONFIRMED = 노선 행이 가리키는 모델(642)
|
|
confirmed = [p for sql, p in db["updates"] if "SET status = 'CONFIRMED'" in sql]
|
|
assert confirmed == [(642, "p1")]
|
|
|
|
|
|
def test_옛_초기값은_지형_그대로_로그_한_줄(tmp_path, caplog):
|
|
_write_dump(tmp_path) # stage1_terrain 칸 없음
|
|
sheet = {"source_filter": "sheet_laplace", "method": "dtm", "smooth": True}
|
|
db = _db(sheet)
|
|
with caplog.at_level(logging.INFO, logger="common_util.common_util_initial_snapshot"):
|
|
asyncio.run(restore_initial_snapshot(_Connection(db), tmp_path, "p1"))
|
|
|
|
assert db["stage1"] == sheet
|
|
assert not [sql for sql, _ in db["updates"] if "surface_models" in sql]
|
|
assert sum("옛 초기값" in r.getMessage() for r in caplog.records) == 1
|