Merge remote-tracking branch 'origin/sub_laptop_4' into main_laptop_1
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
"""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
|
||||
Reference in New Issue
Block a user