Skip to content

Commit

Permalink
Merge pull request #6551 from ales-erjavec/pyqt6-tests-timeouts
Browse files Browse the repository at this point in the history
[MNT] Fix timeout errors in concurrent widgets when running unittests
  • Loading branch information
markotoplak authored Aug 25, 2023
2 parents e1bdd82 + afaa8f9 commit 0a9c762
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
42 changes: 1 addition & 41 deletions Orange/widgets/data/utils/pythoneditor/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion Orange/widgets/data/utils/pythoneditor/tests/test_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 0a9c762

Please sign in to comment.