Merge 21 QTestTreeItem subclasses into a single factory
Replace individual per-type subclass files with a _ITEM_CONFIG dict and make_tree_item() factory in test_tree_item.py. Replace class-name string check in setBreakpoint() with a _no_breakpoint flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,32 +12,7 @@ from time import (time)
|
||||
from main_win.test_tree_items.common import (TEST_COLS, TEST_COLS_WITH_TIME)
|
||||
from lib.tum_except import (ETUMFileError, ETUMSyntaxError)
|
||||
from main_win.test_controller_service import TestControllerService
|
||||
from main_win.test_tree_items.test_tree_git import QTestTreeItemGit
|
||||
|
||||
# to be removed in the future and replaced by a more "sexy" mechanism
|
||||
from main_win.test_tree_items.test_tree_unittest import (QTestTreeItemUnittest,
|
||||
QTestTreeItemUnittestElement)
|
||||
from main_win.test_tree_items.test_tree_sleep import QTestTreeItemSleep
|
||||
from main_win.test_tree_items.test_tree_cycle import QTestTreeItemCycle
|
||||
from main_win.test_tree_items.test_tree_group import QTestTreeItemGroup
|
||||
from main_win.test_tree_items.test_tree_git import QTestTreeItemGit
|
||||
from main_win.test_tree_items.test_tree_py_func import QTestTreeItemPyFunc
|
||||
from main_win.test_tree_items.test_tree_lua_func import QTestTreeItemLuaFunc
|
||||
from main_win.test_tree_items.test_tree_jsonrpc import QTestTreeItemJSONRPC, QTestTreeItemJSONRPCAction
|
||||
from main_win.test_tree_items.test_tree_run import QTestTreeItemRun
|
||||
from main_win.test_tree_items.test_tree_runtime_plot import QTestTreePlot, QTestTreePlotAction
|
||||
from main_win.test_tree_items.test_tree_report import QTestTreeItemReport
|
||||
from main_win.test_tree_items.test_tree_let import QTestTreeItemLet
|
||||
from main_win.test_tree_items.test_tree_check import QTestTreeItemCheckValue
|
||||
from main_win.test_tree_items.test_tree_unittest import QTestTreeItemUnittest, QTestTreeItemUnittestElement
|
||||
from main_win.test_tree_items.test_tree_value_dialog import QTestTreeItemValueDialog
|
||||
from main_win.test_tree_items.test_tree_note_dialog import QTestTreeItemNoteDialog
|
||||
from main_win.test_tree_items.test_tree_image_dialog import QTestTreeItemImageDialog
|
||||
from main_win.test_tree_items.test_tree_msg_dialog import QTestTreeItemMsgDialog
|
||||
from main_win.test_tree_items.test_tree_question_dialog import QTestTreeItemQuestionDialog
|
||||
from main_win.test_tree_items.test_tree_tested_references_dialog import QTestTreeItemTestedRefsDialog
|
||||
from main_win.test_tree_items.test_tree_choices_dialog import QTestTreeItemChoicesDialog
|
||||
from main_win.test_tree_items.test_tree_console import (QTestTreeItemConsole, QTestTreeItemConsoleAction)
|
||||
from main_win.test_tree_items.test_tree_item import make_tree_item
|
||||
|
||||
from interpreter.test_items.test_result import (TestValue)
|
||||
import libs.testium as tm
|
||||
@@ -47,33 +22,8 @@ from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTree(QTreeWidget):
|
||||
breakpoint = Signal()
|
||||
DICT_TREE_ITEMS = {
|
||||
cst.TYPE_UNITTEST_FILE.item_name : QTestTreeItemUnittest,
|
||||
cst.TYPE_UNITTEST_STEP.item_name : QTestTreeItemUnittestElement,
|
||||
cst.TYPE_SLEEP.item_name : QTestTreeItemSleep,
|
||||
cst.TYPE_CYCLE.item_name : QTestTreeItemCycle,
|
||||
cst.TYPE_GRAPH.item_name : QTestTreePlot,
|
||||
cst.TYPE_GRAPH_ACTION.item_name : QTestTreePlotAction,
|
||||
cst.TYPE_GROUP.item_name : QTestTreeItemGroup,
|
||||
cst.TYPE_GIT.item_name : QTestTreeItemGit,
|
||||
cst.TYPE_PY_FUNCTION.item_name : QTestTreeItemPyFunc,
|
||||
cst.TYPE_LUA_FUNCTION.item_name : QTestTreeItemLuaFunc,
|
||||
cst.TYPE_LET.item_name : QTestTreeItemLet,
|
||||
cst.TYPE_CHECK.item_name : QTestTreeItemCheckValue,
|
||||
cst.TYPE_JSON_RPC.item_name : QTestTreeItemJSONRPC,
|
||||
cst.TYPE_JSON_RPC_ACTION.item_name : QTestTreeItemJSONRPCAction,
|
||||
cst.TYPE_RUN.item_name : QTestTreeItemRun,
|
||||
cst.TYPE_REPORT.item_name : QTestTreeItemReport,
|
||||
cst.TYPE_VALUE_DLG.item_name : QTestTreeItemValueDialog,
|
||||
cst.TYPE_NOTE_DLG.item_name : QTestTreeItemNoteDialog,
|
||||
cst.TYPE_IMAGE_DLG.item_name : QTestTreeItemImageDialog,
|
||||
cst.TYPE_MESSAGE_DLG.item_name : QTestTreeItemMsgDialog,
|
||||
cst.TYPE_QUESTION_DLG.item_name : QTestTreeItemQuestionDialog,
|
||||
cst.TYPE_REFERENCE_DLG.item_name : QTestTreeItemTestedRefsDialog,
|
||||
cst.TYPE_CHOICES_DLG.item_name : QTestTreeItemChoicesDialog,
|
||||
cst.TYPE_CONSOLE.item_name : QTestTreeItemConsole,
|
||||
cst.TYPE_CONSOLE_ACTION.item_name : QTestTreeItemConsoleAction,
|
||||
}
|
||||
|
||||
_KNOWN_TYPES = {e.item_name for e in cst}
|
||||
|
||||
|
||||
def __init__(self, parent):
|
||||
@@ -297,12 +247,9 @@ class QTestTree(QTreeWidget):
|
||||
|
||||
for test_id in test_set_item.keys():
|
||||
childType = test_set_item[test_id]["type"]
|
||||
if childType in self.DICT_TREE_ITEMS.keys():
|
||||
tree_item = self.DICT_TREE_ITEMS[childType](tree_parent,
|
||||
test_set_item[test_id],
|
||||
self.cols)
|
||||
else:
|
||||
if childType not in self._KNOWN_TYPES:
|
||||
raise ETUMSyntaxError(f"Error in the test_set, type {childType} undefined")
|
||||
tree_item = make_tree_item(tree_parent, test_set_item[test_id], self.cols)
|
||||
|
||||
cb = QComboBox(self)
|
||||
self.setItemWidget(tree_item, self.cols['desc']['index'], cb)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemCheckValue(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/verif.png")
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemChoicesDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/label.png")
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemConsole(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.recursive_unfoldable = False
|
||||
self.setRowIcon(icon_prefix() + "/terminal.png")
|
||||
|
||||
class QTestTreeItemConsoleAction(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/terminal.png")
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemCycle(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/cycle.png")
|
||||
self.setExpanded(True)
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemGit(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/git.png")
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemGroup(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/group.png")
|
||||
self.setExpanded(True)
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemImageDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/image.png")
|
||||
|
||||
@@ -7,6 +7,56 @@ from PySide6.QtWidgets import (QTreeWidgetItem)
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
from libs.testium import print_warn
|
||||
|
||||
# Maps item_name (from TestItemType.item_name) to visual config.
|
||||
# Keys: icon (required), icon_on (optional 2nd state), expanded, unfoldable, no_breakpoint
|
||||
_ITEM_CONFIG = {
|
||||
"unittest file": {"icon": "folder.png", "icon_on": "folder-open.png", "expanded": True, "no_breakpoint": True},
|
||||
"unittest step": {"icon": "document.png", "no_breakpoint": True},
|
||||
"Console": {"icon": "terminal.png", "unfoldable": False},
|
||||
"Console action": {"icon": "terminal.png"},
|
||||
"Cycle": {"icon": "cycle.png", "expanded": True},
|
||||
"python Function": {"icon": "python.png"},
|
||||
"lua Function": {"icon": "lua.png"},
|
||||
"Report": {"icon": "report.png"},
|
||||
"git repository": {"icon": "git.png"},
|
||||
"Runtime plot": {"icon": "plot.png"},
|
||||
"Runtime plot action": {"icon": "plot.png"},
|
||||
"Group": {"icon": "group.png", "expanded": True},
|
||||
"Image Dialog": {"icon": "image.png"},
|
||||
"Message Dialog": {"icon": "info.png"},
|
||||
"Let": {"icon": "let.png"},
|
||||
"Check value": {"icon": "verif.png"},
|
||||
"Note Dialog": {"icon": "note.png"},
|
||||
"Question Dialog": {"icon": "question.png"},
|
||||
"Sleep": {"icon": "sleep.png"},
|
||||
"References Dialog": {"icon": "label.png"},
|
||||
"Value Dialog": {"icon": "question.png"},
|
||||
"Choices Dialog": {"icon": "label.png"},
|
||||
"Run tum": {"icon": "testium_logo.svg"},
|
||||
"JSON-RPC": {"icon": "json.png", "unfoldable": False},
|
||||
"JSON-RPC action": {"icon": "json.png"},
|
||||
}
|
||||
|
||||
|
||||
def make_tree_item(parent, test_set_item, cols):
|
||||
"""Factory: create a QTestTreeItem configured for the given test_set_item type."""
|
||||
item = QTestTreeItem(parent, test_set_item, cols)
|
||||
cfg = _ITEM_CONFIG.get(test_set_item["type"], {})
|
||||
if cfg.get("unfoldable") is False:
|
||||
item.recursive_unfoldable = False
|
||||
if cfg.get("expanded"):
|
||||
item.setExpanded(True)
|
||||
if cfg.get("no_breakpoint"):
|
||||
item._no_breakpoint = True
|
||||
icon = cfg.get("icon", "")
|
||||
if icon:
|
||||
icon_on = cfg.get("icon_on", "")
|
||||
item.setRowIcon(
|
||||
icon_prefix() + "/" + icon,
|
||||
icon_prefix() + "/" + icon_on if icon_on else "",
|
||||
)
|
||||
return item
|
||||
|
||||
|
||||
def __iter__QTreeWidgetItem(self):
|
||||
for item in chain(*map(iter, self.children())):
|
||||
@@ -51,6 +101,7 @@ class QTestTreeItem(QTreeWidgetItem):
|
||||
self._is_highlighted = False
|
||||
self._initial_brush = None
|
||||
self._failure_list = None
|
||||
self._no_breakpoint = False
|
||||
parent.addChild(self)
|
||||
self._has_failed = False
|
||||
self._display_pause = False
|
||||
@@ -106,9 +157,7 @@ class QTestTreeItem(QTreeWidgetItem):
|
||||
self.setIcon(self._cols["status"]["index"], icon)
|
||||
|
||||
def setBreakpoint(self):
|
||||
if (self.__class__.__name__ == "QTestTreeItemUnittest") or (
|
||||
self.__class__.__name__ == "QTestTreeItemUnittestElement"
|
||||
):
|
||||
if self._no_breakpoint:
|
||||
return
|
||||
self._display_pause = not self._display_pause
|
||||
if self._display_pause:
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemJSONRPCAction(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/json.png")
|
||||
|
||||
class QTestTreeItemJSONRPC(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.recursive_unfoldable = False
|
||||
self.setRowIcon(icon_prefix() + "/json.png")
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemLet(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/let.png")
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemLuaFunc(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/lua.png")
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemMsgDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/info.png")
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemNoteDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/note.png")
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemPyFunc(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/python.png")
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemQuestionDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/question.png")
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemReport(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/report.png")
|
||||
@@ -1,8 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemRun(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/testium_logo.svg")
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreePlotAction(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/plot.png")
|
||||
|
||||
class QTestTreePlot(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/plot.png")
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemSleep(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/sleep.png")
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemTestedRefsDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/label.png")
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemUnittest(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/folder.png", icon_prefix() + "/folder-open.png")
|
||||
self.setExpanded(True)
|
||||
|
||||
class QTestTreeItemUnittestElement(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
self.setRowIcon(icon_prefix() + "/document.png")
|
||||
@@ -1,10 +0,0 @@
|
||||
|
||||
from .test_tree_item import QTestTreeItem
|
||||
from interpreter.utils.icons import icon_prefix
|
||||
|
||||
class QTestTreeItemValueDialog(QTestTreeItem):
|
||||
def __init__(self, parent, test_set_item, cols):
|
||||
super().__init__(parent, test_set_item, cols)
|
||||
|
||||
self.setRowIcon(icon_prefix() + "/question.png")
|
||||
|
||||
Reference in New Issue
Block a user