Fix block and line name resetting upon saving document
- Изменены методы renumber_lines и renumber_blocks в models.py: теперь они переименовывают только стандартные (дефолтные) названия блоков/линий. - Кастомные названия блоков и линий теперь полностью сохраняются при переиндексации (на сохранении). - Добавлен интеграционный тест на сохранение/загрузку кастомных имен линий и блоков в qa_smoke.py.
This commit is contained in:
parent
65d7580977
commit
91189d6d37
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
from collections import deque
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@ -635,7 +636,8 @@ class MappingDocument:
|
||||
old_id = line.id
|
||||
id_map[old_id] = new_id
|
||||
line.id = new_id
|
||||
line.name = f"Линия {new_id}"
|
||||
if not line.name or re.match(r"^(Линия|Line)\s+\d+$", line.name):
|
||||
line.name = f"Линия {new_id}"
|
||||
line.color = default_color(new_id)
|
||||
|
||||
for point in self.points:
|
||||
@ -904,7 +906,8 @@ class MappingDocument:
|
||||
def renumber_blocks(line: LedLine) -> None:
|
||||
for block_number, block in enumerate(line.blocks, start=1):
|
||||
block.id = block_number
|
||||
block.name = f"Блок {block_number}"
|
||||
if not block.name or re.match(r"^(Блок|Block)\s+\d+$", block.name):
|
||||
block.name = f"Блок {block_number}"
|
||||
|
||||
|
||||
def sorted_unique(values: list[int]) -> list[int]:
|
||||
|
||||
16
qa_smoke.py
16
qa_smoke.py
@ -1106,6 +1106,22 @@ def test_line_renaming_and_tree_shortcuts() -> None:
|
||||
line.name = "Верхняя Линия"
|
||||
assert line.name == "Верхняя Линия"
|
||||
|
||||
block = window.document.add_block(line.id, [])
|
||||
block.name = "Левое Крыло"
|
||||
assert block.name == "Левое Крыло"
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
save_path = Path(temp_dir) / "test_save.json"
|
||||
window.document.save(save_path)
|
||||
|
||||
from models import MappingDocument
|
||||
new_doc = MappingDocument()
|
||||
new_doc.load(save_path)
|
||||
assert len(new_doc.lines) == 1
|
||||
assert new_doc.lines[0].name == "Верхняя Линия"
|
||||
assert len(new_doc.lines[0].blocks) == 1
|
||||
assert new_doc.lines[0].blocks[0].name == "Левое Крыло"
|
||||
|
||||
assert "tree_rename" in window.actions
|
||||
assert "tree_delete" in window.actions
|
||||
assert "tree_merge" in window.actions
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user