Files
Aislo/resources/tester/test_m02_drawing_area.py
T
eomsangdonandClaude Opus 5.5 05226dd9e5 feat(B07): 도각 읽는 차례 = 프로젝트 작업본 → 없으면 시스템 · [도각 편집] 저장은 작업본 · [기본 도각으로] = 프로젝트 _initial (PLAN 10-3 · 10-5)
- Engine_Template — M02_Template_Layers 자리 함수로 읽고 씀 · 회사 층(storage/{회사}/templates/) 읽기 뺌
- use_project_templates · save_project_template · reset_project_template(_initial 없으면 작업본 지움) · is_project_template_customized
- Router · Router_Frame — 프로젝트 폴더를 넘김
- 도각 편집 띠 · 되돌리기 글을 프로젝트 도각으로
- 시험 test_m02_drawing_area.py — 옛 프로젝트 · 씨앗 뿌린 프로젝트 저장 · 되돌리기

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PxvYb5ufV1kWdBvZbpDfu6
2026-09-25 09:47:30 +09:00

107 lines
4.0 KiB
Python

"""M02 도면 양식 — 작도 영역 칸 · B07 도각 층(프로젝트 작업본 → 시스템) (PLAN 10-3)."""
import json
from B07_DesignDetail import B07_DesignDetail_Engine_Template as engine
from M02_MasterTemplete import M02_Template_Layers as layers
A1 = engine.A1_TEMPLATE
def _project_template(project_root, document):
path = engine.project_template_path(project_root)
path.parent.mkdir(parents=True)
path.write_text(json.dumps(document), encoding="utf-8")
return path
def _entities(project_root):
engine.use_project_templates(project_root)
try:
return engine.template_entities()
finally:
engine.use_project_templates(None)
def test_system_a1_reads_drawing_area():
engine.use_project_templates(None)
assert engine.drawing_area() == (42.0, 47.0, 812.0, 567.0)
assert len(engine.template_entities()) == 51
def test_missing_area_falls_back_to_a1(tmp_path):
_project_template(tmp_path, {"format": 6, "entities": [], "layers": []})
engine.use_project_templates(tmp_path)
try:
assert engine.drawing_area() == engine._A1_INNER
finally:
engine.use_project_templates(None)
def test_template_area_moves_content(tmp_path):
line = {
"id": "a",
"type": "Line",
"shapeData": {"startPoint": {"x": 0, "y": 0}, "endPoint": {"x": 10, "y": 0}},
}
_project_template(
tmp_path,
{"format": 6, "drawing_area": [0, 0, 400, 200], "entities": [line], "layers": []},
)
engine.use_project_templates(tmp_path)
try:
assert engine.drawing_area() == (0.0, 0.0, 400.0, 200.0)
assert engine.usable_area() == (400 * 0.96, 200 * 0.96)
# 콘텐츠 중심(500, 500) 이 작도 영역 중심(200, 100) 에 온다 — 이동량 (300, 400).
placed = engine.frame_entities("t", (490.0, 490.0, 510.0, 510.0), fit=False)
assert placed[0]["shapeData"]["startPoint"] == {"x": 300.0, "y": 400.0}
finally:
engine.use_project_templates(None)
def test_bad_area_falls_back(tmp_path):
_project_template(tmp_path, {"drawing_area": [10, 10, 5, 5], "entities": []})
engine.use_project_templates(tmp_path)
try:
assert engine.drawing_area() == engine._A1_INNER
finally:
engine.use_project_templates(None)
def test_old_project_reads_system(tmp_path):
# 작업본이 없는 옛 프로젝트 — 시스템 양식으로 떨어진다.
assert len(_entities(tmp_path)) == 51
assert engine.is_project_template_customized(tmp_path) is False
def test_save_reset_on_seeded_project(tmp_path):
layers.seed_project(tmp_path)
assert engine.project_template_path(tmp_path).is_file()
assert engine.is_project_template_customized(tmp_path) is False
# [완료] — 작업본에만 쓴다 · 작도 영역은 이어 받는다 · `_initial/` · 시스템은 그대로.
path = engine.save_project_template(tmp_path, [])
saved = json.loads(path.read_text(encoding="utf-8"))
assert saved["drawing_area"] == [42, 47, 812, 567]
assert _entities(tmp_path) == []
assert engine.is_project_template_customized(tmp_path) is True
initial = layers.template_path(layers.initial_dir(tmp_path), "drawing", A1)
assert len(json.loads(initial.read_text(encoding="utf-8"))["entities"]) == 51
assert (
len(json.loads(engine.system_template_path().read_text(encoding="utf-8"))["entities"]) == 51
)
# [기본 도각으로] — `_initial/` 을 작업본에 덮어쓴다.
assert engine.reset_project_template(tmp_path) is True
assert len(_entities(tmp_path)) == 51
assert engine.is_project_template_customized(tmp_path) is False
def test_reset_on_old_project_drops_to_system(tmp_path):
engine.save_project_template(tmp_path, [])
assert _entities(tmp_path) == []
assert engine.reset_project_template(tmp_path) is True
assert not engine.project_template_path(tmp_path).exists()
assert len(_entities(tmp_path)) == 51
assert engine.reset_project_template(tmp_path) is False