From afaa8f95b2ff5028848923ef7525e110680ec374 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Fri, 25 Aug 2023 11:55:32 +0200 Subject: [PATCH] Fix TimeoutErrors in concurrent widgets when running unittests This seems to be caused by pythoneditor test's use of 'in_main_loop' decorator. --- .../data/utils/pythoneditor/tests/base.py | 42 +------------------ .../utils/pythoneditor/tests/test_edit.py | 1 - 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/Orange/widgets/data/utils/pythoneditor/tests/base.py b/Orange/widgets/data/utils/pythoneditor/tests/base.py index ca331a8ba60..a6625e3674c 100644 --- a/Orange/widgets/data/utils/pythoneditor/tests/base.py +++ b/Orange/widgets/data/utils/pythoneditor/tests/base.py @@ -7,12 +7,9 @@ as published by the Free Software Foundation, version 2.1 of the license. This is compatible with Orange3's GPL-3.0 license. """ # pylint: disable=duplicate-code -import time - -from AnyQt.QtCore import QTimer from AnyQt.QtGui import QKeySequence from AnyQt.QtTest import QTest -from AnyQt.QtCore import Qt, QCoreApplication +from AnyQt.QtCore import Qt from orangewidget.utils import enum_as_int @@ -21,43 +18,6 @@ from Orange.widgets.tests.base import GuiTest -def _processPendingEvents(app): - """Process pending application events. - Timeout is used, because on Windows hasPendingEvents() always returns True - """ - t = time.time() - while time.time() - t < 0.1: - app.processEvents() - - -def in_main_loop(func, *_): - """Decorator executes test method in the QApplication main loop. - QAction shortcuts doesn't work, if main loop is not running. - Do not use for tests, which doesn't use main loop, because it slows down execution. - """ - def wrapper(*args): - app = QCoreApplication.instance() - self = args[0] - - def execWithArgs(): - self.qpart.show() - QTest.qWaitForWindowExposed(self.qpart) - _processPendingEvents(app) - - try: - func(*args) - finally: - _processPendingEvents(app) - app.quit() - - QTimer.singleShot(0, execWithArgs) - - app.exec_() - - wrapper.__name__ = func.__name__ # for unittest test runner - return wrapper - - class EditorTest(GuiTest): def setUp(self) -> None: super().setUp() diff --git a/Orange/widgets/data/utils/pythoneditor/tests/test_edit.py b/Orange/widgets/data/utils/pythoneditor/tests/test_edit.py index bd90bf03666..def27aa76e8 100755 --- a/Orange/widgets/data/utils/pythoneditor/tests/test_edit.py +++ b/Orange/widgets/data/utils/pythoneditor/tests/test_edit.py @@ -40,7 +40,6 @@ def test_overwrite_backspace(self): QTest.keyClick(self.qpart, Qt.Key_Backspace) self.assertEqual(self.qpart.text, 'a d') - @base.in_main_loop def test_overwrite_undo(self): self.qpart.show() self.qpart.text = 'abcd'