From 0327080352b1109022f2629eab12c012da882379 Mon Sep 17 00:00:00 2001 From: monsieuremre Date: Sat, 15 Jun 2024 15:37:07 +0000 Subject: [PATCH 1/4] Implement test script --- test.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..2831c15 --- /dev/null +++ b/test.py @@ -0,0 +1,77 @@ +# Copyright (C) Igor Garmaev, IAT der RWTH Aachen +# +# This program is made available under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# A copy of the GNU General Public License is available at http://www.gnu.org/licenses/ + +import sys +import logging +import time +import signal +from PyQt6.QtCore import Qt, pyqtSignal, QModelIndex, QTimer, QAbstractItemModel, QPoint +from PyQt6.QtGui import QClipboard, QPalette, QColor, QMouseEvent, QKeyEvent, QAction +from PyQt6 import QtWidgets +from aas_editor import * + +logging.basicConfig(level=logging.INFO, filename="log.log", filemode="w", + format="%(asctime)s | %(levelname)s | %(message)s") + + +# class TimeOutException(Exception): +# pass +# +# +# def alarm_handler(signum, frame): +# raise TimeOutException() + + +logging.basicConfig(level=logging.INFO, filename="log.log", filemode="w", + format="%(asctime)s | %(levelname)s | %(message)s") + + +def main(): + app = QtWidgets.QApplication(sys.argv) + + from aas_editor.editorApp import EditorApp as CurrentApp + from basyx.aas.model import Submodel + + fileToOpen = sys.argv[1] if len(sys.argv) > 1 else None + window = CurrentApp(fileToOpen) + window.show() + + tree = window.mainTreeView + tree.expandAll() + model = tree.model() + root = model.index(0, 0) + + if root.isValid(): + root_data = model.data(root) + print(f"Iterating Through {root_data}") + for row in range(model.rowCount(root)): + item_index = model.index(row, 0, root) + item_data = model.data(item_index) + print(f"Itering Items Under {item_data}") + for subrow in range(model.rowCount(item_index)): + subitem_index = model.index(subrow, 0, item_index) + subitem_data = model.data(subitem_index) + print(f"Item: {subitem_data}") + + # if item_data == "submodels": + # signal.signal(signal.SIGALRM, alarm_handler) + # signal.alarm(1) + # try: + # print("Add dialog for a new submodel") + # tree.addItemWithDialog(item_data, Submodel) + # except: + # print("Dialog timed out") + # signal.alarm(0) + app.exec() + + +if __name__ == "__main__": + + main() From 2cdad5b2eda309ac0f1dead8a29fe1a4cb19b690 Mon Sep 17 00:00:00 2001 From: monsieuremre Date: Sun, 30 Jun 2024 14:58:10 +0000 Subject: [PATCH 2/4] pytest implement --- test.py | 135 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 83 insertions(+), 52 deletions(-) diff --git a/test.py b/test.py index 2831c15..48b22c5 100644 --- a/test.py +++ b/test.py @@ -10,68 +10,99 @@ import sys import logging -import time -import signal -from PyQt6.QtCore import Qt, pyqtSignal, QModelIndex, QTimer, QAbstractItemModel, QPoint -from PyQt6.QtGui import QClipboard, QPalette, QColor, QMouseEvent, QKeyEvent, QAction -from PyQt6 import QtWidgets -from aas_editor import * - -logging.basicConfig(level=logging.INFO, filename="log.log", filemode="w", - format="%(asctime)s | %(levelname)s | %(message)s") +import pytest -# class TimeOutException(Exception): -# pass -# -# -# def alarm_handler(signum, frame): -# raise TimeOutException() - +from PyQt6 import QtWidgets +from PyQt6 import QtWebEngineWidgets +from PyQt6.QtWidgets import * +from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QAbstractButton +from PyQt6.QtCore import Qt +from PyQt6.QtTest import QTest logging.basicConfig(level=logging.INFO, filename="log.log", filemode="w", format="%(asctime)s | %(levelname)s | %(message)s") - -def main(): - app = QtWidgets.QApplication(sys.argv) - +@pytest.fixture +def app(qtbot): + app = QtWidgets.QApplication("./main.py") + return app + +def find_button_by_text(widget, text): + if isinstance(widget, QToolButton) and widget.text() == text: + return widget + + for child in widget.findChildren(QWidget): + result = find_button_by_text(child, text) + if result: + return result + + return None + +def find_menu_by_text(widget, text): + if isinstance(widget, QMenu) and widget.title() == text: + return widget + + for child in widget.findChildren(QWidget): + result = find_menu_by_text(child, text) + if result: + return result + + return None + +def print_widgets_text(widget, depth=0): + if isinstance(widget, QMenu): + print(" " * depth + widget.title()) + elif isinstance(widget, QToolButton): + print(" " * depth + widget.text()) + else: + print(" " * depth + widget.objectName() + " - " + widget.metaObject().className()) + + for child in widget.findChildren(QWidget): + print_widgets_text(child, depth + 1) + +def click_widget(widget): + if widget: + QTest.mouseClick(widget, Qt.LeftButton) + +def test_gui(qtbot): from aas_editor.editorApp import EditorApp as CurrentApp - from basyx.aas.model import Submodel - - fileToOpen = sys.argv[1] if len(sys.argv) > 1 else None - window = CurrentApp(fileToOpen) + window = CurrentApp("./test.aasx") window.show() - + qtbot.addWidget(window) + qtbot.waitUntil(window.isVisible) + assert window.isVisible(), f"Window not visible" + tree = window.mainTreeView tree.expandAll() model = tree.model() - root = model.index(0, 0) if root.isValid(): - root_data = model.data(root) - print(f"Iterating Through {root_data}") - for row in range(model.rowCount(root)): - item_index = model.index(row, 0, root) - item_data = model.data(item_index) - print(f"Itering Items Under {item_data}") - for subrow in range(model.rowCount(item_index)): - subitem_index = model.index(subrow, 0, item_index) - subitem_data = model.data(subitem_index) - print(f"Item: {subitem_data}") - - # if item_data == "submodels": - # signal.signal(signal.SIGALRM, alarm_handler) - # signal.alarm(1) - # try: - # print("Add dialog for a new submodel") - # tree.addItemWithDialog(item_data, Submodel) - # except: - # print("Dialog timed out") - # signal.alarm(0) - app.exec() - - -if __name__ == "__main__": - - main() + root_data = model.data(root) + print(f"Iterating Through {root_data}") + for row in range(model.rowCount(root)): + item_index = model.index(row, 0, root) + item_data = model.data(item_index) + print(f"Itering Items Under {item_data}") + for subrow in range(model.rowCount(item_index)): + subitem_index = model.index(subrow, 0, item_index) + subitem_data = model.data(subitem_index) + print(f"Item: {subitem_data}") + + + + subm = find_menu_by_text(window, "Add existing submodel") + click_widget(subm) + + QTest.keyPress(window, Qt.Key_N, Qt.ControlModifier) + QTest.keyRelease(window, Qt.Key_N, Qt.ControlModifier) + + current_focus_window = None + + for widget in QApplication.topLevelWidgets(): + #print(widget) + if widget.isActiveWindow(): + current_focus_window = widget + break + + #print(current_focus_window) From 606a0749cbc7ac99775afa1f53939e8e0cb17a2c Mon Sep 17 00:00:00 2001 From: monsieuremre Date: Sun, 7 Jul 2024 14:13:32 +0000 Subject: [PATCH 3/4] no pytest --- test.py | 158 +++++++++++++++++++++++++++----------------------------- 1 file changed, 77 insertions(+), 81 deletions(-) diff --git a/test.py b/test.py index 48b22c5..a24c5ae 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -# Copyright (C) Igor Garmaev, IAT der RWTH Aachen +# Copyright (C) 2021 Igor Garmaev, garmaev@gmx.net # # This program is made available under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at your option) any later version. @@ -10,99 +10,95 @@ import sys import logging - -import pytest +import time from PyQt6 import QtWidgets -from PyQt6 import QtWebEngineWidgets from PyQt6.QtWidgets import * -from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QAbstractButton +from PyQt6 import QtWebEngineWidgets from PyQt6.QtCore import Qt from PyQt6.QtTest import QTest +from basyx.aas.model import AssetAdministrationShell, ConceptDescription, Submodel, Property, \ + Entity, Capability, Operation, RelationshipElement, AnnotatedRelationshipElement, Range, Blob, File, \ + ReferenceElement, DataElement, AdministrativeInformation, AbstractObjectStore, \ + Namespace, SubmodelElementCollection, SubmodelElement, ModelReference, Referable, Identifiable, \ + Key, Qualifier, BasicEventElement, SubmodelElementList, datatypes, LangStringSet, DictObjectStore + + logging.basicConfig(level=logging.INFO, filename="log.log", filemode="w", format="%(asctime)s | %(levelname)s | %(message)s") - -@pytest.fixture -def app(qtbot): - app = QtWidgets.QApplication("./main.py") - return app -def find_button_by_text(widget, text): - if isinstance(widget, QToolButton) and widget.text() == text: - return widget - - for child in widget.findChildren(QWidget): - result = find_button_by_text(child, text) - if result: - return result - - return None +def find_focused_widget(): + app = QApplication.instance() + if app is not None: + focused_widget = app.focusWidget() + if focused_widget is not None: + print("Widget with focus:", focused_widget) + else: + print("No widget currently has focus.") + +def main(): + app = QtWidgets.QApplication(sys.argv) + from aas_editor.editorApp import EditorApp as CurrentApp -def find_menu_by_text(widget, text): - if isinstance(widget, QMenu) and widget.title() == text: - return widget - - for child in widget.findChildren(QWidget): - result = find_menu_by_text(child, text) - if result: - return result + fileToOpen = sys.argv[1] if len(sys.argv) > 1 else None - return None + window = CurrentApp(fileToOpen) -def print_widgets_text(widget, depth=0): - if isinstance(widget, QMenu): - print(" " * depth + widget.title()) - elif isinstance(widget, QToolButton): - print(" " * depth + widget.text()) - else: - print(" " * depth + widget.objectName() + " - " + widget.metaObject().className()) - - for child in widget.findChildren(QWidget): - print_widgets_text(child, depth + 1) - -def click_widget(widget): - if widget: - QTest.mouseClick(widget, Qt.LeftButton) - -def test_gui(qtbot): - from aas_editor.editorApp import EditorApp as CurrentApp - window = CurrentApp("./test.aasx") window.show() - qtbot.addWidget(window) - qtbot.waitUntil(window.isVisible) - assert window.isVisible(), f"Window not visible" - + window.mainTreeView.setFocus() + tree = window.mainTreeView - tree.expandAll() - model = tree.model() - - if root.isValid(): - root_data = model.data(root) - print(f"Iterating Through {root_data}") - for row in range(model.rowCount(root)): - item_index = model.index(row, 0, root) - item_data = model.data(item_index) - print(f"Itering Items Under {item_data}") - for subrow in range(model.rowCount(item_index)): - subitem_index = model.index(subrow, 0, item_index) - subitem_data = model.data(subitem_index) - print(f"Item: {subitem_data}") - - - - subm = find_menu_by_text(window, "Add existing submodel") - click_widget(subm) - - QTest.keyPress(window, Qt.Key_N, Qt.ControlModifier) - QTest.keyRelease(window, Qt.Key_N, Qt.ControlModifier) - current_focus_window = None - - for widget in QApplication.topLevelWidgets(): - #print(widget) - if widget.isActiveWindow(): - current_focus_window = widget - break + prev_time = time.time() + while True: + app.processEvents() + current_time = time.time() + if int(current_time) != int(prev_time): + + tree = window.mainTreeView + + tree.setFocusPolicy(Qt.StrongFocus) + QTest.mouseClick(tree, Qt.LeftButton) + tree.setFocus(Qt.NoFocusReason) + + tree.expandAll() + + model = tree.model() + root = model.index(0, 0) - #print(current_focus_window) + if (int(current_time) - int(prev_time)) > 10: + break + + elif root.isValid(): + root_data = model.data(root) + print(f"Iterating Through {root_data}") + for row in range(model.rowCount(root)): + item_index = model.index(row, 0, root) + item_data = model.data(item_index) + + if item_data == 'submodels': + tree.setCurrentIndex(item_index) + app.processEvents() + time.sleep(1) + from aas_editor import dialogs + dialog = dialogs.AddObjDialog(Submodel, parent=tree, objVal=None, title='', rmDefParams=False) + dialog.show() + app.processEvents() + dialog.accept() + obj = tree._getObjFromDialog(dialog) + dialog.deleteLater() + result = tree._setItemData(item_index, obj, 1130) + + time.sleep(1) + app.processEvents() + time.sleep(1) + + tree.onDelClear() + + time.sleep(1) + app.processEvents() + time.sleep(1) + +if __name__ == "__main__": + main() From 520182fe671c979fc3c196319849e9dfab17e7ad Mon Sep 17 00:00:00 2001 From: monsieuremre Date: Sun, 7 Jul 2024 14:23:40 +0000 Subject: [PATCH 4/4] testing very bigly --- test.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/test.py b/test.py index a24c5ae..de59b81 100644 --- a/test.py +++ b/test.py @@ -18,6 +18,7 @@ from PyQt6.QtCore import Qt from PyQt6.QtTest import QTest + from basyx.aas.model import AssetAdministrationShell, ConceptDescription, Submodel, Property, \ Entity, Capability, Operation, RelationshipElement, AnnotatedRelationshipElement, Range, Blob, File, \ ReferenceElement, DataElement, AdministrativeInformation, AbstractObjectStore, \ @@ -52,6 +53,7 @@ def main(): prev_time = time.time() while True: + from aas_editor import dialogs app.processEvents() current_time = time.time() if int(current_time) != int(prev_time): @@ -67,7 +69,7 @@ def main(): model = tree.model() root = model.index(0, 0) - if (int(current_time) - int(prev_time)) > 10: + if (int(current_time) - int(prev_time)) > 100: break elif root.isValid(): @@ -81,9 +83,13 @@ def main(): tree.setCurrentIndex(item_index) app.processEvents() time.sleep(1) - from aas_editor import dialogs dialog = dialogs.AddObjDialog(Submodel, parent=tree, objVal=None, title='', rmDefParams=False) dialog.show() + + time.sleep(1) + app.processEvents() + time.sleep(1) + app.processEvents() dialog.accept() obj = tree._getObjFromDialog(dialog) @@ -99,6 +105,57 @@ def main(): time.sleep(1) app.processEvents() time.sleep(1) + + elif item_data == 'shells': + tree.setCurrentIndex(item_index) + app.processEvents() + dialog = dialogs.AddObjDialog(AssetAdministrationShell, parent=tree, objVal=None, title='', rmDefParams=False) + dialog.show() + + time.sleep(1) + app.processEvents() + time.sleep(1) + + dialog.reject() + dialog.deleteLater() + + time.sleep(1) + app.processEvents() + time.sleep(1) + + elif item_data == 'fileStore': + tree.setCurrentIndex(item_index) + app.processEvents() + dialog = dialogs.AddObjDialog(File, parent=tree, objVal=None, title='', rmDefParams=False) + dialog.show() + + time.sleep(1) + app.processEvents() + time.sleep(1) + + dialog.reject() + dialog.deleteLater() + + time.sleep(1) + app.processEvents() + time.sleep(1) + + elif item_data == 'concept_descriptions': + tree.setCurrentIndex(item_index) + app.processEvents() + dialog = dialogs.AddObjDialog(ConceptDescription, parent=tree, objVal=None, title='', rmDefParams=False) + dialog.show() + + time.sleep(1) + app.processEvents() + time.sleep(1) + + dialog.reject() + dialog.deleteLater() + + time.sleep(1) + app.processEvents() + time.sleep(1) if __name__ == "__main__": main()