diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-04 12:00:16 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-09 13:20:15 +0200 |
commit | 27efa8e4bc074efb0c05fc1462a8b46d60e5256b (patch) | |
tree | 3cd62a299ff56241a6cf55e10fb152cbf4d24121 /sources/pyside6/tests/QtCore | |
parent | 140b7df1263e2d24d1fc69b8ad305e8189d1dadc (diff) |
Port the QtCore signals tests to modern syntax
Use the modern syntax where appropriate. Some tests are
left unmodified to at least test the syntax.
Pick-to: 6.7
Task-number: PYSIDE-2646
Change-Id: Idb16cda65ab1985f8be5fa5527b5a19e26fcec34
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/tests/QtCore')
6 files changed, 53 insertions, 43 deletions
diff --git a/sources/pyside6/tests/QtCore/blocking_signals_test.py b/sources/pyside6/tests/QtCore/blocking_signals_test.py index d8159c2ef..493abb071 100644 --- a/sources/pyside6/tests/QtCore/blocking_signals_test.py +++ b/sources/pyside6/tests/QtCore/blocking_signals_test.py @@ -14,7 +14,12 @@ 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, SIGNAL, QFile, QSignalBlocker +from PySide6.QtCore import QObject, Signal, QFile, QSignalBlocker + + +class Sender(QObject): + mysignal = Signal() + mysignal_int_int = Signal(int, int) class TestSignalsBlockedBasic(unittest.TestCase): @@ -61,7 +66,7 @@ class TestSignalsBlocked(unittest.TestCase): def setUp(self): # Set up the basic resources needed - self.obj = QObject() + self.obj = Sender() self.args = tuple() self.called = False @@ -81,27 +86,28 @@ class TestSignalsBlocked(unittest.TestCase): def testShortCircuitSignals(self): # Blocking of Python short-circuit signals - QObject.connect(self.obj, SIGNAL('mysignal()'), self.callback) + self.obj.mysignal.connect(self.callback) - self.obj.emit(SIGNAL('mysignal()')) + self.obj.mysignal.emit() self.assertTrue(self.called) self.called = False self.obj.blockSignals(True) - self.obj.emit(SIGNAL('mysignal()')) + self.obj.mysignal.emit() self.assertTrue(not self.called) def testPythonSignals(self): # Blocking of Python typed signals - QObject.connect(self.obj, SIGNAL('mysignal(int,int)'), self.callback) + + self.obj.mysignal_int_int.connect(self.callback) self.args = (1, 3) - self.obj.emit(SIGNAL('mysignal(int,int)'), *self.args) + self.obj.mysignal_int_int.emit(*self.args) self.assertTrue(self.called) self.called = False self.obj.blockSignals(True) - self.obj.emit(SIGNAL('mysignal(int,int)'), *self.args) + self.obj.mysignal_int_int.emit(*self.args) self.assertTrue(not self.called) @@ -130,7 +136,7 @@ class TestQFileSignalBlocking(unittest.TestCase): def testAboutToCloseBlocking(self): # QIODevice.aboutToClose() blocking - QObject.connect(self.qfile, SIGNAL('aboutToClose()'), self.callback) + self.qfile.aboutToClose.connect(self.callback) self.assertTrue(self.qfile.open(QFile.ReadOnly)) self.qfile.close() diff --git a/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py b/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py index c5a6736a8..84859af84 100644 --- a/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py +++ b/sources/pyside6/tests/QtCore/bug_PYSIDE-164.py @@ -10,16 +10,19 @@ 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 QCoreApplication, QEventLoop, QObject, Qt, QThread, QTimer, SIGNAL +from PySide6.QtCore import QCoreApplication, QEventLoop, QObject, Qt, QThread, Signal class Emitter(QThread): + + signal = Signal(int) + def __init__(self): super().__init__() def run(self): print("Before emit.") - self.emit(SIGNAL("signal(int)"), 0) + self.signal.emit(0) print("After emit.") @@ -36,12 +39,11 @@ class Receiver(QObject): class TestBugPYSIDE164(unittest.TestCase): def testBlockingSignal(self): - app = QCoreApplication.instance() or QCoreApplication([]) + app = QCoreApplication.instance() or QCoreApplication([]) # noqa: F841 eventloop = QEventLoop() emitter = Emitter() receiver = Receiver(eventloop) - emitter.connect(emitter, SIGNAL("signal(int)"), - receiver.receive, Qt.BlockingQueuedConnection) + emitter.signal.connect(receiver.receive, Qt.BlockingQueuedConnection) emitter.start() retval = eventloop.exec() emitter.wait(2000) diff --git a/sources/pyside6/tests/QtCore/qmetaobject_test.py b/sources/pyside6/tests/QtCore/qmetaobject_test.py index 8f6467a07..4b3051711 100644 --- a/sources/pyside6/tests/QtCore/qmetaobject_test.py +++ b/sources/pyside6/tests/QtCore/qmetaobject_test.py @@ -105,15 +105,6 @@ class qmetaobject_test(unittest.TestCase): o.connect(o2, SIGNAL("bars()"), o.slot) self.assertTrue(o2.metaObject().indexOfMethod("bars()") > -1) - #self.assertTrue(o.metaObject().indexOfMethod("bar()") == -1) - #self.assertTrue(o.metaObject().indexOfMethod("slot()") > -1) - - #slot_index = o.metaObject().indexOfMethod("slot()") - - #o.connect(o, SIGNAL("foo()"), o2, SIGNAL("bar()")) - #signal_index = o.metaObject().indexOfMethod("foo()"); - - #self.assertTrue(slot_index != signal_index) # PYSIDE-784, plain Qt objects should not have intermediary # metaObjects. @@ -125,7 +116,7 @@ class qmetaobject_test(unittest.TestCase): # PYSIDE-1827, slots with non-QObject object types should work # (metatypes are registered) def test_ObjectSlotSignal(self): - app = QCoreApplication() + app = QCoreApplication() # noqa: F841 sender = SemaphoreSender() receiver = SemaphoreReceiver() sender.signal.connect(receiver.receiverSlot, Qt.QueuedConnection) diff --git a/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py b/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py index b93408d10..b3bfaf007 100644 --- a/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py +++ b/sources/pyside6/tests/QtCore/qobject_connect_notify_test.py @@ -12,7 +12,7 @@ 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, SIGNAL, SLOT +from PySide6.QtCore import QObject, Signal, SIGNAL, SLOT from helper.usesqapplication import UsesQApplication @@ -21,6 +21,9 @@ def cute_slot(): class Obj(QObject): + + foo = Signal() + def __init__(self): super().__init__() self.con_notified = False @@ -51,37 +54,44 @@ class TestQObjectConnectNotify(UsesQApplication): def testBasic(self): sender = Obj() receiver = QObject() + sender.destroyed.connect(receiver.deleteLater) + self.assertTrue(sender.con_notified) + self.assertEqual(sender.signal.methodSignature(), "destroyed()") + self.assertTrue(sender.destroyed.disconnect(receiver.deleteLater)) + self.assertTrue(sender.dis_notified) + + def testBasicString(self): + sender = Obj() + receiver = QObject() sender.connect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()")) self.assertTrue(sender.con_notified) # When connecting to a regular slot, and not a python callback function, QObject::connect # will use the non-cloned method signature, so connecting to destroyed() will actually # connect to destroyed(QObject*). self.assertEqual(sender.signal.methodSignature(), "destroyed(QObject*)") - sender.disconnect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()")) + self.assertTrue(sender.disconnect(SIGNAL("destroyed()"), receiver, SLOT("deleteLater()"))) self.assertTrue(sender.dis_notified) def testPySignal(self): sender = Obj() receiver = QObject() - sender.connect(SIGNAL("foo()"), receiver, SLOT("deleteLater()")) + sender.foo.connect(receiver.deleteLater) self.assertTrue(sender.con_notified) - sender.disconnect(SIGNAL("foo()"), receiver, SLOT("deleteLater()")) + self.assertTrue(sender.foo.disconnect(receiver.deleteLater)) self.assertTrue(sender.dis_notified) def testPySlots(self): sender = Obj() - receiver = QObject() - sender.connect(SIGNAL("destroyed()"), cute_slot) + sender.destroyed.connect(cute_slot) self.assertTrue(sender.con_notified) - sender.disconnect(SIGNAL("destroyed()"), cute_slot) + self.assertTrue(sender.destroyed.disconnect(cute_slot)) self.assertTrue(sender.dis_notified) def testpyAll(self): sender = Obj() - receiver = QObject() - sender.connect(SIGNAL("foo()"), cute_slot) + sender.foo.connect(cute_slot) self.assertTrue(sender.con_notified) - sender.disconnect(SIGNAL("foo()"), cute_slot) + self.assertTrue(sender.foo.disconnect(cute_slot)) self.assertTrue(sender.dis_notified) diff --git a/sources/pyside6/tests/QtCore/qslot_object_test.py b/sources/pyside6/tests/QtCore/qslot_object_test.py index 061ce9160..a95afb090 100644 --- a/sources/pyside6/tests/QtCore/qslot_object_test.py +++ b/sources/pyside6/tests/QtCore/qslot_object_test.py @@ -11,7 +11,7 @@ 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 QCoreApplication, QObject, QTimer, SIGNAL, SLOT +from PySide6.QtCore import QCoreApplication, QObject, QTimer """ This is a simple slot test that was updated to use the qApp "macro". @@ -28,24 +28,23 @@ class objTest(QObject): def slot(self): self.ok = True - qApp.quit() + qApp.quit() # noqa: F821 class slotTest(unittest.TestCase): def quit_app(self): - qApp.quit() + qApp.quit() # noqa: F821 def testBasic(self): timer = QTimer() timer.setInterval(100) my_obj = objTest() - my_slot = SLOT("slot()") - QObject.connect(timer, SIGNAL("timeout()"), my_obj, my_slot) + timer.timeout.connect(my_obj.slot) timer.start(100) QTimer.singleShot(1000, self.quit_app) - qApp.exec() + qApp.exec() # noqa: F821 self.assertTrue(my_obj.ok) diff --git a/sources/pyside6/tests/QtCore/thread_signals_test.py b/sources/pyside6/tests/QtCore/thread_signals_test.py index b0a5f0186..a453d1ac1 100644 --- a/sources/pyside6/tests/QtCore/thread_signals_test.py +++ b/sources/pyside6/tests/QtCore/thread_signals_test.py @@ -12,14 +12,16 @@ 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, SIGNAL, QFile, QThread, QTimer, Qt +from PySide6.QtCore import Signal, QThread from helper.usesqapplication import UsesQApplication class MyThread(QThread): + test = Signal(str) + def run(self): - self.emit(SIGNAL("test(const QString&)"), "INdT - PySide") + self.test.emit("INdT - PySide") class TestThreadSignal(UsesQApplication): @@ -33,7 +35,7 @@ class TestThreadSignal(UsesQApplication): def testThread(self): t = MyThread() - QObject.connect(t, SIGNAL("test(const QString&)"), self._callback) + t.test.connect(self._callback) t.start() self.app.exec() |