aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtCore/qtimer_singleshot_test.py')
-rw-r--r--sources/pyside6/tests/QtCore/qtimer_singleshot_test.py117
1 files changed, 108 insertions, 9 deletions
diff --git a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
index e702f4792..2ccaa300e 100644
--- a/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
+++ b/sources/pyside6/tests/QtCore/qtimer_singleshot_test.py
@@ -14,8 +14,8 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QObject, QTimer, QCoreApplication, Signal
-from helper.usesqcoreapplication import UsesQCoreApplication
+from PySide6.QtCore import QObject, QThread, QTimer, Signal, Slot, SLOT
+from helper.usesqapplication import UsesQApplication
class WatchDog(QObject):
@@ -32,14 +32,28 @@ class WatchDog(QObject):
self.watched.exit_app_cb()
-class TestSingleShot(UsesQCoreApplication):
+class ThreadForContext(QThread):
+ def __init__(self):
+ super().__init__()
+ self.called = False
+ self.qthread = None
+ self.context = QObject()
+
+ def run(self):
+ self.called = True
+ self.qthread = QThread.currentThread()
+ self.exec()
+
+
+class TestSingleShot(UsesQApplication):
'''Test case for QTimer.singleShot'''
def setUp(self):
# Acquire resources
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
self.watchdog = WatchDog(self)
self.called = False
+ self.qthread = None
def tearDown(self):
# Release resources
@@ -47,10 +61,12 @@ class TestSingleShot(UsesQCoreApplication):
del self.called
# PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
gc.collect()
- UsesQCoreApplication.tearDown(self)
+ UsesQApplication.tearDown(self)
def callback(self):
self.called = True
+ self.qthread = QThread.currentThread()
+ self.qthread.exit()
self.app.quit()
def testSingleShot(self):
@@ -58,17 +74,94 @@ class TestSingleShot(UsesQCoreApplication):
self.app.exec()
self.assertTrue(self.called)
+ def testSingleShotZero(self):
+ QTimer.singleShot(0, self.callback)
+ self.app.exec()
+ self.assertTrue(self.called)
+
+ def testSingleShotWithContext(self):
+ thread = ThreadForContext()
+ thread.start()
+ thread.context.moveToThread(thread)
+ QTimer.singleShot(100, thread.context, self.callback)
+ self.app.exec()
+ thread.wait()
+ self.assertTrue(self.called)
+ self.assertTrue(thread.called)
+ self.assertEqual(self.qthread, thread.qthread)
+
+ def testSingleShotWithContextZero(self):
+ thread = ThreadForContext()
+ thread.start()
+ thread.context.moveToThread(thread)
+ QTimer.singleShot(0, thread.context, self.callback)
+ self.app.exec()
+ thread.wait()
+ self.assertTrue(self.called)
+ self.assertTrue(thread.called)
+ self.assertEqual(self.qthread, thread.qthread)
+
+
+class TestSingleShotCallableObject(UsesQApplication):
+ '''Test case for QTimer.singleShot with callable inside an object'''
+
+ def setUp(self):
+ # Acquire resources
+ UsesQApplication.setUp(self)
+ self.watchdog = WatchDog(self)
+
+ def tearDown(self):
+ # Release resources
+ del self.watchdog
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
+ UsesQApplication.tearDown(self)
+
+ class CallbackObject(QObject):
+ def __init__(self, app) -> None:
+ super().__init__()
+ self.app = app
+
+ @Slot()
+ def func(self):
+ self.called = True
+ self.app.quit()
+
+ def testSingleShotWithObjectAndMember(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(100, callback, SLOT("func()"))
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithObjectAndMemberZero(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(0, callback, SLOT("func()"))
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithCallableInObject(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(100, callback.func)
+ self.app.exec()
+ self.assertTrue(callback.called)
+
+ def testSingleShotWithCallableInObjectZero(self):
+ callback = self.CallbackObject(self.app)
+ QTimer.singleShot(0, callback.func)
+ self.app.exec()
+ self.assertTrue(callback.called)
+
class SigEmitter(QObject):
sig1 = Signal()
-class TestSingleShotSignal(UsesQCoreApplication):
+class TestSingleShotSignal(UsesQApplication):
'''Test case for QTimer.singleShot connecting to signals'''
def setUp(self):
- UsesQCoreApplication.setUp(self)
+ UsesQApplication.setUp(self)
self.watchdog = WatchDog(self)
self.called = False
@@ -77,7 +170,7 @@ class TestSingleShotSignal(UsesQCoreApplication):
del self.called
# PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
gc.collect()
- UsesQCoreApplication.tearDown(self)
+ UsesQApplication.tearDown(self)
def callback(self):
self.called = True
@@ -90,7 +183,13 @@ class TestSingleShotSignal(UsesQCoreApplication):
self.app.exec()
self.assertTrue(self.called)
+ def testSingleShotSignalZero(self):
+ emitter = SigEmitter()
+ emitter.sig1.connect(self.callback)
+ QTimer.singleShot(0, emitter.sig1)
+ self.app.exec()
+ self.assertTrue(self.called)
+
if __name__ == '__main__':
unittest.main()
-