diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-03 13:44:51 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-09 13:20:13 +0200 |
| commit | 140b7df1263e2d24d1fc69b8ad305e8189d1dadc (patch) | |
| tree | 0f414ea7a55bd8407651ddb0441e0c05ed2e8f79 /sources/pyside6 | |
| parent | f619b4c45b042c3a656a80b57cb4f154ef15bd1a (diff) | |
Port signals tests to modern syntax
Use the modern syntax where appropriate. Some tests are
left unmodified to at least test the syntax.
As a drive-by, remove the hasQtGui import checks since
widgets should be built when this is run.
Pick-to: 6.7
Task-number: PYSIDE-2646
Change-Id: I9acf07d0b735009f6aff4a55382dae745d855786
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6')
20 files changed, 403 insertions, 396 deletions
diff --git a/sources/pyside6/tests/signals/args_dont_match_test.py b/sources/pyside6/tests/signals/args_dont_match_test.py index e200cedbc..4f56be348 100644 --- a/sources/pyside6/tests/signals/args_dont_match_test.py +++ b/sources/pyside6/tests/signals/args_dont_match_test.py @@ -11,7 +11,11 @@ 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 +from PySide6.QtCore import QObject, Signal + + +class Sender(QObject): + the_signal = Signal(int, int, int) class ArgsDontMatch(unittest.TestCase): @@ -21,9 +25,9 @@ class ArgsDontMatch(unittest.TestCase): def testConnectSignalToSlotWithLessArgs(self): self.ok = False - obj1 = QObject() - QObject.connect(obj1, SIGNAL('the_signal(int, int, int)'), self.callback) - obj1.emit(SIGNAL('the_signal(int, int, int)'), 1, 2, 3) + obj1 = Sender() + obj1.the_signal.connect(self.callback) + obj1.the_signal.emit(1, 2, 3) self.assertTrue(self.ok) diff --git a/sources/pyside6/tests/signals/bug_312.py b/sources/pyside6/tests/signals/bug_312.py index 8b4d65c55..80d56a020 100644 --- a/sources/pyside6/tests/signals/bug_312.py +++ b/sources/pyside6/tests/signals/bug_312.py @@ -11,44 +11,29 @@ 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 +from PySide6.QtCore import QObject, Signal MAX_LOOPS = 5 MAX_OBJECTS = 200 -class Dummy(object): - def __init__(self, parent): - self._parent = parent - - def callback(self): - self._called = True +class Sender(QObject): + fire = Signal() class MultipleSlots(unittest.TestCase): def myCB(self): self._count += 1 - """ - def testUnboundSignal(self): - o = QObject() - self._count = 0 - for i in range(MAX_OBJECTS): - QObject.connect(o, SIGNAL("fire()"), lambda: self.myCB()) - - o.emit(SIGNAL("fire()")) - self.assertEqual(self._count, MAX_OBJECTS) - - """ def testDisconnectCleanup(self): for c in range(MAX_LOOPS): self._count = 0 self._senders = [] for i in range(MAX_OBJECTS): - o = QObject() - QObject.connect(o, SIGNAL("fire()"), lambda: self.myCB()) + o = Sender() + o.fire.connect(lambda: self.myCB()) self._senders.append(o) - o.emit(SIGNAL("fire()")) + o.fire.emit() self.assertEqual(self._count, MAX_OBJECTS) diff --git a/sources/pyside6/tests/signals/decorators_test.py b/sources/pyside6/tests/signals/decorators_test.py index 5b3b54690..b29339ee4 100644 --- a/sources/pyside6/tests/signals/decorators_test.py +++ b/sources/pyside6/tests/signals/decorators_test.py @@ -11,7 +11,11 @@ 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, Slot, SIGNAL, SLOT +from PySide6.QtCore import QObject, Slot, Signal + + +class Sender(QObject): + mySignal = Signal() class MyObject(QObject): @@ -57,9 +61,10 @@ class StaticMetaObjectTest(unittest.TestCase): self.assertTrue(m.indexOfSlot('mySlot4(QString,int)') > 0) def testEmission(self): + sender = Sender() o = MyObject() - o.connect(SIGNAL("mySignal()"), o, SLOT("mySlot()")) - o.emit(SIGNAL("mySignal()")) + sender.mySignal.connect(o.mySlot) + sender.mySignal.emit() self.assertTrue(o._slotCalledCount == 1) def testResult(self): diff --git a/sources/pyside6/tests/signals/invalid_callback_test.py b/sources/pyside6/tests/signals/invalid_callback_test.py index 61ba444e5..2788c1d1a 100644 --- a/sources/pyside6/tests/signals/invalid_callback_test.py +++ b/sources/pyside6/tests/signals/invalid_callback_test.py @@ -13,7 +13,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 +from PySide6.QtCore import QObject class InvalidCallback(unittest.TestCase): @@ -34,8 +34,7 @@ class InvalidCallback(unittest.TestCase): def testIntegerCb(self): # Test passing an int as callback to QObject.connect - self.assertRaises(TypeError, QObject.connect, self.obj, - SIGNAL('destroyed()'), 42) + self.assertRaises(TypeError, self.obj.destroyed.connect, 42) if __name__ == '__main__': diff --git a/sources/pyside6/tests/signals/lambda_gui_test.py b/sources/pyside6/tests/signals/lambda_gui_test.py index 736b800bf..2123e7206 100644 --- a/sources/pyside6/tests/signals/lambda_gui_test.py +++ b/sources/pyside6/tests/signals/lambda_gui_test.py @@ -12,43 +12,39 @@ 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 - -try: - from PySide6.QtWidgets import QSpinBox, QPushButton - hasQtGui = True -except ImportError: - hasQtGui = False +from PySide6.QtWidgets import QSpinBox, QPushButton from helper.usesqapplication import UsesQApplication -if hasQtGui: - class Control: - def __init__(self): - self.arg = False - - class QtGuiSigLambda(UsesQApplication): - - def testButton(self): - # Connecting a lambda to a QPushButton.clicked() - obj = QPushButton('label') - ctr = Control() - func = lambda: setattr(ctr, 'arg', True) # noqa: E731 - obj.clicked.connect(func) - obj.click() - self.assertTrue(ctr.arg) - QObject.disconnect(obj, SIGNAL('clicked()'), func) - - def testSpinButton(self): - # Connecting a lambda to a QPushButton.clicked() - obj = QSpinBox() - ctr = Control() - arg = 444 - func = lambda x: setattr(ctr, 'arg', 444) # noqa: E731 - obj.valueChanged.connect(func) - obj.setValue(444) - self.assertEqual(ctr.arg, arg) - QObject.disconnect(obj, SIGNAL('valueChanged(int)'), func) + +class Control: + def __init__(self): + self.arg = False + + +class QtWidgetsSigLambda(UsesQApplication): + + def testButton(self): + # Connecting a lambda to a QPushButton.clicked() + obj = QPushButton('label') + ctr = Control() + func = lambda: setattr(ctr, 'arg', True) # noqa: E731 + obj.clicked.connect(func) + obj.click() + self.assertTrue(ctr.arg) + self.assertTrue(obj.clicked.disconnect(func)) + + def testSpinButton(self): + # Connecting a lambda to a QPushButton.clicked() + obj = QSpinBox() + ctr = Control() + arg = 444 + func = lambda x: setattr(ctr, 'arg', 444) # noqa: E731 + obj.valueChanged.connect(func) + obj.setValue(444) + self.assertEqual(ctr.arg, arg) + self.assertTrue(obj.valueChanged.disconnect(func)) + if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/signals/multiple_connections_gui_test.py b/sources/pyside6/tests/signals/multiple_connections_gui_test.py index 4afb3daff..295369b7d 100644 --- a/sources/pyside6/tests/signals/multiple_connections_gui_test.py +++ b/sources/pyside6/tests/signals/multiple_connections_gui_test.py @@ -10,22 +10,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 - -try: - from PySide6.QtWidgets import QPushButton, QSpinBox - hasQtGui = True -except ImportError: - hasQtGui = False +from PySide6.QtWidgets import QPushButton, QSpinBox from helper.basicpyslotcase import BasicPySlotCase from helper.usesqapplication import UsesQApplication -class MultipleSignalConnections(unittest.TestCase): - '''Base class for multiple signal connection testing''' +class QtGuiMultipleSlots(UsesQApplication): + '''Multiple connections to QtGui signals''' - def run_many(self, sender, signal, emitter, receivers, args=None): + def run_many(self, signal, emitter, receivers, args=None): """Utility method to connect a list of receivers to a signal. sender - QObject that will emit the signal signal - string with the signal signature @@ -39,7 +33,7 @@ class MultipleSignalConnections(unittest.TestCase): for rec in receivers: rec.setUp() - QObject.connect(sender, SIGNAL(signal), rec.cb) + signal.connect(rec.cb) rec.args = tuple(args) emitter(*args) @@ -47,24 +41,20 @@ class MultipleSignalConnections(unittest.TestCase): for rec in receivers: self.assertTrue(rec.called) + def testButtonClick(self): + """Multiple connections to QPushButton.clicked()""" + sender = QPushButton('button') + receivers = [BasicPySlotCase() for x in range(30)] + self.run_many(sender.clicked, sender.click, receivers) -if hasQtGui: - class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections): - '''Multiple connections to QtGui signals''' - - def testButtonClick(self): - """Multiple connections to QPushButton.clicked()""" - sender = QPushButton('button') - receivers = [BasicPySlotCase() for x in range(30)] - self.run_many(sender, 'clicked()', sender.click, receivers) + def testSpinBoxValueChanged(self): + """Multiple connections to QSpinBox.valueChanged(int)""" + sender = QSpinBox() + # FIXME if number of receivers if higher than 50, segfaults + receivers = [BasicPySlotCase() for x in range(10)] + self.run_many(sender.valueChanged, sender.setValue, + receivers, (1,)) - def testSpinBoxValueChanged(self): - """Multiple connections to QSpinBox.valueChanged(int)""" - sender = QSpinBox() - # FIXME if number of receivers if higher than 50, segfaults - receivers = [BasicPySlotCase() for x in range(10)] - self.run_many(sender, 'valueChanged(int)', sender.setValue, - receivers, (1,)) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/signals/multiple_connections_test.py b/sources/pyside6/tests/signals/multiple_connections_test.py index b6aa33f2d..233851797 100644 --- a/sources/pyside6/tests/signals/multiple_connections_test.py +++ b/sources/pyside6/tests/signals/multiple_connections_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 QObject, SIGNAL, QProcess +from PySide6.QtCore import QObject, Signal, QProcess from helper.basicpyslotcase import BasicPySlotCase from helper.usesqapplication import UsesQApplication @@ -20,7 +20,7 @@ from helper.usesqapplication import UsesQApplication class MultipleSignalConnections(unittest.TestCase): '''Base class for multiple signal connection testing''' - def run_many(self, sender, signal, emitter, receivers, args=None): + def run_many(self, signal, emitter, receivers, args=None): """Utility method to connect a list of receivers to a signal. sender - QObject that will emit the signal signal - string with the signal signature @@ -33,7 +33,7 @@ class MultipleSignalConnections(unittest.TestCase): args = tuple() for rec in receivers: rec.setUp() - self.assertTrue(QObject.connect(sender, SIGNAL(signal), rec.cb)) + self.assertTrue(signal.connect(rec.cb)) rec.args = tuple(args) emitter(*args) @@ -48,13 +48,14 @@ class PythonMultipleSlots(UsesQApplication, MultipleSignalConnections): def testPythonSignal(self): """Multiple connections to a python signal (short-circuit)""" - class Dummy(QObject): - pass + class Sender(QObject): - sender = Dummy() + foobar = Signal(int) + + sender = Sender() receivers = [BasicPySlotCase() for x in range(10)] - self.run_many(sender, 'foobar(int)', partial(sender.emit, - SIGNAL('foobar(int)')), receivers, (0, )) + self.run_many(sender.foobar, partial(sender.foobar.emit), + receivers, (0, )) class QProcessMultipleSlots(UsesQApplication, MultipleSignalConnections): @@ -67,9 +68,10 @@ class QProcessMultipleSlots(UsesQApplication, MultipleSignalConnections): def start_proc(*args): sender.start(sys.executable, ['-c', '""']) - sender.waitForFinished() + self.assertTrue(sender.waitForStarted()) + self.assertTrue(sender.waitForFinished()) - self.run_many(sender, 'started()', start_proc, receivers) + self.run_many(sender.started, start_proc, receivers) def testQProcessFinished(self): '''Multiple connections to QProcess.finished(int)''' @@ -78,9 +80,10 @@ class QProcessMultipleSlots(UsesQApplication, MultipleSignalConnections): def start_proc(*args): sender.start(sys.executable, ['-c', '""']) - sender.waitForFinished() + self.assertTrue(sender.waitForStarted()) + self.assertTrue(sender.waitForFinished()) - self.run_many(sender, 'finished(int)', start_proc, receivers, (0,)) + self.run_many(sender.finished, start_proc, receivers, (0, QProcess.ExitStatus.NormalExit)) if __name__ == '__main__': diff --git a/sources/pyside6/tests/signals/pysignal_test.py b/sources/pyside6/tests/signals/pysignal_test.py index 61dd537a5..d6f44edf8 100644 --- a/sources/pyside6/tests/signals/pysignal_test.py +++ b/sources/pyside6/tests/signals/pysignal_test.py @@ -11,31 +11,31 @@ 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, Qt - -try: - from PySide6.QtWidgets import QSpinBox, QApplication, QWidget # noqa: F401 - hasQtGui = True -except ImportError: - hasQtGui = False +from PySide6.QtCore import QObject, Signal, Qt +from PySide6.QtWidgets import QSpinBox, QApplication, QWidget # noqa: F401 from helper.usesqapplication import UsesQApplication -class Dummy(QObject): - """Dummy class used in this test.""" +TEST_LIST = ["item1", "item2", "item3"] + + +class Sender(QObject): + """Sender class used in this test.""" + + foo = Signal() + foo_int = Signal(int) + dummy = Signal(str) + dummy2 = Signal(str, list) + def __init__(self, parent=None): - QObject.__init__(self, parent) + super().__init__(parent) def callDummy(self): - self.emit(SIGNAL("dummy(PyObject)"), "PyObject") + self.dummy.emit("PyObject") def callDummy2(self): - lst = [] - lst.append("item1") - lst.append("item2") - lst.append("item3") - self.emit(SIGNAL("dummy2(PyObject, PyObject)"), "PyObject0", lst) + self.dummy2.emit("PyObject0", TEST_LIST) class PyObjectType(UsesQApplication): @@ -46,35 +46,33 @@ class PyObjectType(UsesQApplication): def mySlot2(self, arg0, arg1): self.assertEqual(arg0, "PyObject0") - self.assertEqual(arg1[0], "item1") - self.assertEqual(arg1[1], "item2") - self.assertEqual(arg1[2], "item3") + self.assertEqual(arg1, TEST_LIST) self.callCount += 1 if self.running: self.app.quit() def setUp(self): - super(PyObjectType, self).setUp() + super().setUp() self.callCount = 0 self.running = False def testWithOneArg(self): - o = Dummy() - o.connect(SIGNAL("dummy(PyObject)"), self.mySlot) + o = Sender() + o.dummy.connect(self.mySlot) o.callDummy() self.assertEqual(self.callCount, 1) def testWithTwoArg(self): - o = Dummy() - o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2) + o = Sender() + o.dummy2.connect(self.mySlot2) o.callDummy2() self.assertEqual(self.callCount, 1) def testAsyncSignal(self): self.called = False self.running = True - o = Dummy() - o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2, Qt.QueuedConnection) + o = Sender() + o.dummy2.connect(self.mySlot2, Qt.QueuedConnection) o.callDummy2() self.app.exec() self.assertEqual(self.callCount, 1) @@ -82,8 +80,8 @@ class PyObjectType(UsesQApplication): def testTwice(self): self.called = False self.running = True - o = Dummy() - o.connect(SIGNAL("dummy2(PyObject,PyObject)"), self.mySlot2, Qt.QueuedConnection) + o = Sender() + o.dummy2.connect(self.mySlot2, Qt.QueuedConnection) o.callDummy2() o.callDummy2() self.app.exec() @@ -108,98 +106,98 @@ class PythonSigSlot(unittest.TestCase): def testNoArgs(self): """Python signal and slots without arguments""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo()'), self.callback) + obj1.foo.connect(self.callback) self.args = tuple() - obj1.emit(SIGNAL('foo()'), *self.args) + obj1.foo.emit(*self.args) self.assertTrue(self.called) def testWithArgs(self): """Python signal and slots with integer arguments""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo(int)'), self.callback) + obj1.foo_int.connect(self.callback) self.args = (42,) - obj1.emit(SIGNAL('foo(int)'), *self.args) + obj1.foo_int.emit(*self.args) self.assertTrue(self.called) def testDisconnect(self): - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo(int)'), self.callback) - QObject.disconnect(obj1, SIGNAL('foo(int)'), self.callback) + obj1.foo_int.connect(self.callback) + self.assertTrue(obj1.foo_int.disconnect(self.callback)) self.args = (42, ) - obj1.emit(SIGNAL('foo(int)'), *self.args) + obj1.foo_int.emit(*self.args) self.assertTrue(not self.called) -if hasQtGui: - class SpinBoxPySignal(UsesQApplication): - """Tests the connection of python signals to QSpinBox qt slots.""" +class SpinBoxPySignal(UsesQApplication): + """Tests the connection of python signals to QSpinBox qt slots.""" - def setUp(self): - super(SpinBoxPySignal, self).setUp() - self.obj = Dummy() - self.spin = QSpinBox() - self.spin.setValue(0) + def setUp(self): + super().setUp() + self.obj = Sender() + self.spin = QSpinBox() + self.spin.setValue(0) - def tearDown(self): - super(SpinBoxPySignal, self).tearDown() - del self.obj - del self.spin - # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion - gc.collect() + def tearDown(self): + super().tearDown() + del self.obj + del self.spin + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + + def testValueChanged(self): + """Emission of a python signal to QSpinBox setValue(int)""" - def testValueChanged(self): - """Emission of a python signal to QSpinBox setValue(int)""" - QObject.connect(self.obj, SIGNAL('dummy(int)'), self.spin, SLOT('setValue(int)')) - self.assertEqual(self.spin.value(), 0) + self.obj.foo_int.connect(self.spin.setValue) + self.assertEqual(self.spin.value(), 0) - self.obj.emit(SIGNAL('dummy(int)'), 4) - self.assertEqual(self.spin.value(), 4) + self.obj.foo_int.emit(4) + self.assertEqual(self.spin.value(), 4) - def testValueChangedMultiple(self): - """Multiple emissions of a python signal to QSpinBox setValue(int)""" - QObject.connect(self.obj, SIGNAL('dummy(int)'), self.spin, SLOT('setValue(int)')) - self.assertEqual(self.spin.value(), 0) + def testValueChangedMultiple(self): + """Multiple emissions of a python signal to QSpinBox setValue(int)""" + self.obj.foo_int.connect(self.spin.setValue) + self.assertEqual(self.spin.value(), 0) - self.obj.emit(SIGNAL('dummy(int)'), 4) - self.assertEqual(self.spin.value(), 4) + self.obj.foo_int.emit(4) + self.assertEqual(self.spin.value(), 4) - self.obj.emit(SIGNAL('dummy(int)'), 77) - self.assertEqual(self.spin.value(), 77) + self.obj.foo_int.emit(77) + self.assertEqual(self.spin.value(), 77) -if hasQtGui: - class WidgetPySignal(UsesQApplication): - """Tests the connection of python signals to QWidget qt slots.""" +class WidgetPySignal(UsesQApplication): + """Tests the connection of python signals to QWidget qt slots.""" + + def setUp(self): + super(WidgetPySignal, self).setUp() + self.obj = Sender() + self.widget = QWidget() - def setUp(self): - super(WidgetPySignal, self).setUp() - self.obj = Dummy() - self.widget = QWidget() + def tearDown(self): + super(WidgetPySignal, self).tearDown() + del self.obj + del self.widget + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() - def tearDown(self): - super(WidgetPySignal, self).tearDown() - del self.obj - del self.widget - # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion - gc.collect() + def testShow(self): + """Emission of a python signal to QWidget slot show()""" + self.widget.hide() - def testShow(self): - """Emission of a python signal to QWidget slot show()""" - self.widget.hide() + self.obj.foo.connect(self.widget.show) + self.assertTrue(not self.widget.isVisible()) - QObject.connect(self.obj, SIGNAL('dummy()'), self.widget, SLOT('show()')) - self.assertTrue(not self.widget.isVisible()) + self.obj.foo.emit() + self.assertTrue(self.widget.isVisible()) - self.obj.emit(SIGNAL('dummy()')) - self.assertTrue(self.widget.isVisible()) if __name__ == '__main__': unittest.main() diff --git a/sources/pyside6/tests/signals/qobject_sender_test.py b/sources/pyside6/tests/signals/qobject_sender_test.py index 485584ec2..9c1121eb8 100644 --- a/sources/pyside6/tests/signals/qobject_sender_test.py +++ b/sources/pyside6/tests/signals/qobject_sender_test.py @@ -13,7 +13,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 +from PySide6.QtCore import QCoreApplication, QObject, QTimer, Signal from helper.usesqapplication import UsesQApplication @@ -22,6 +22,10 @@ class ExtQTimer(QTimer): super().__init__() +class Sender(QObject): + foo = Signal() + + class Receiver(QObject): def __init__(self): super().__init__() @@ -37,10 +41,10 @@ class ObjectSenderTest(unittest.TestCase): '''Test case for QObject.sender() method.''' def testSenderPythonSignal(self): - sender = QObject() + sender = Sender() recv = Receiver() - QObject.connect(sender, SIGNAL('foo()'), recv.callback) - sender.emit(SIGNAL('foo()')) + sender.foo.connect(recv.callback) + sender.foo.emit() self.assertEqual(sender, recv.the_sender) @@ -48,10 +52,10 @@ class ObjectSenderCheckOnReceiverTest(unittest.TestCase): '''Test case for QObject.sender() method, this one tests the equality on the Receiver object.''' def testSenderPythonSignal(self): - sender = QObject() + sender = Sender() recv = Receiver() - QObject.connect(sender, SIGNAL('foo()'), recv.callback) - sender.emit(SIGNAL('foo()')) + sender.foo.connect(recv.callback) + sender.foo.emit() self.assertEqual(sender, recv.the_sender) diff --git a/sources/pyside6/tests/signals/segfault_proxyparent_test.py b/sources/pyside6/tests/signals/segfault_proxyparent_test.py index 7107b8278..cb0df0978 100644 --- a/sources/pyside6/tests/signals/segfault_proxyparent_test.py +++ b/sources/pyside6/tests/signals/segfault_proxyparent_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 QObject, SIGNAL +from PySide6.QtCore import QObject, Signal # Description of the problem # After creating an PyObject that inherits from QObject, connecting it, @@ -20,16 +20,19 @@ from PySide6.QtCore import QObject, SIGNAL # Somehow the underlying QObject also points to the same position. -# In PyQt4, the connection works fine with the same memory behavior, -# so it looks like specific to SIP. +class Sender(QObject): + + bar = Signal(int) -class Dummy(QObject): def __init__(self, parent=None): QObject.__init__(self, parent) class Joe(QObject): + + bar = Signal(int) + def __init__(self, parent=None): QObject.__init__(self, parent) @@ -55,19 +58,19 @@ class SegfaultCase(unittest.TestCase): def testSegfault(self): """Regression: Segfault for qobjects in the same memory position.""" - obj = Dummy() - QObject.connect(obj, SIGNAL('bar(int)'), self.callback) + obj = Sender() + obj.bar.connect(self.callback) self.args = (33,) - obj.emit(SIGNAL('bar(int)'), self.args[0]) + obj.bar.emit(self.args[0]) self.assertTrue(self.called) del obj # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion gc.collect() obj = Joe() - QObject.connect(obj, SIGNAL('bar(int)'), self.callback) + obj.bar.connect(self.callback) self.args = (33,) - obj.emit(SIGNAL('bar(int)'), self.args[0]) + obj.bar.emit(self.args[0]) self.assertTrue(self.called) diff --git a/sources/pyside6/tests/signals/self_connect_test.py b/sources/pyside6/tests/signals/self_connect_test.py index 296e1dabb..08ca725f8 100644 --- a/sources/pyside6/tests/signals/self_connect_test.py +++ b/sources/pyside6/tests/signals/self_connect_test.py @@ -13,7 +13,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, Slot, SIGNAL, SLOT +from PySide6.QtCore import QObject, Slot from PySide6.QtWidgets import QPushButton, QWidget from helper.usesqapplication import UsesQApplication @@ -33,7 +33,7 @@ class SelfConnect(UsesQApplication): def testButtonClickClose(self): button = QPushButton() - button.connect(button, SIGNAL('clicked()'), SLOT('close()')) + button.clicked.connect(button.close) button.show() self.assertTrue(button.isVisible()) @@ -43,7 +43,7 @@ class SelfConnect(UsesQApplication): def testWindowButtonClickClose(self): button = QPushButton() window = QWidget() - window.connect(button, SIGNAL('clicked()'), SLOT('close()')) + button.clicked.connect(window.close) window.show() self.assertTrue(window.isVisible()) diff --git a/sources/pyside6/tests/signals/short_circuit_test.py b/sources/pyside6/tests/signals/short_circuit_test.py index e9d64e69b..1ad4bc24c 100644 --- a/sources/pyside6/tests/signals/short_circuit_test.py +++ b/sources/pyside6/tests/signals/short_circuit_test.py @@ -11,11 +11,17 @@ 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 +from PySide6.QtCore import QObject, Signal -class Dummy(QObject): - """Dummy class used in this test.""" +class Sender(QObject): + """Sender class used in this test.""" + + foo = Signal() + foo_int = Signal(int) + foo_int_int_string = Signal(int, int, str) + foo_int_qobject = Signal(int, QObject) + def __init__(self, parent=None): QObject.__init__(self, parent) @@ -38,40 +44,40 @@ class ShortCircuitSignals(unittest.TestCase): def testNoArgs(self): """Short circuit signal without arguments""" - obj1 = Dummy() - QObject.connect(obj1, SIGNAL('foo()'), self.callback) + obj1 = Sender() + obj1.foo.connect(self.callback) self.args = tuple() - obj1.emit(SIGNAL('foo()'), *self.args) + obj1.foo.emit(*self.args) self.assertTrue(self.called) def testWithArgs(self): """Short circuit signal with integer arguments""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo(int)'), self.callback) + obj1.foo_int.connect(self.callback) self.args = (42,) - obj1.emit(SIGNAL('foo(int)'), *self.args) + obj1.foo_int.emit(*self.args) self.assertTrue(self.called) def testMultipleArgs(self): """Short circuit signal with multiple arguments""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo(int,int,QString)'), self.callback) + obj1.foo_int_int_string.connect(self.callback) self.args = (42, 33, 'char') - obj1.emit(SIGNAL('foo(int,int,QString)'), *self.args) + obj1.foo_int_int_string.emit(*self.args) self.assertTrue(self.called) def testComplexArgs(self): """Short circuit signal with complex arguments""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo(int,QObject*)'), self.callback) + obj1.foo_int_qobject.connect(self.callback) self.args = (42, obj1) - obj1.emit(SIGNAL('foo(int,QObject*)'), *self.args) + obj1.foo_int_qobject.emit(*self.args) self.assertTrue(self.called) diff --git a/sources/pyside6/tests/signals/signal2signal_connect_test.py b/sources/pyside6/tests/signals/signal2signal_connect_test.py index 8ace7f8cb..31129f7a1 100644 --- a/sources/pyside6/tests/signals/signal2signal_connect_test.py +++ b/sources/pyside6/tests/signals/signal2signal_connect_test.py @@ -13,7 +13,20 @@ 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 +from PySide6.QtCore import QObject, Signal + + +class Sender(QObject): + + mysignal_int = Signal(int) + mysignal_int_int = Signal(int, int) + mysignal_string = Signal(str) + + +class Forwarder(Sender): + + forward = Signal() + forward_qobject = Signal(QObject) def cute_slot(): @@ -25,8 +38,8 @@ class TestSignal2SignalConnect(unittest.TestCase): def setUp(self): # Set up the basic resources needed - self.sender = QObject() - self.forwarder = QObject() + self.sender = Sender() + self.forwarder = Forwarder() self.args = None self.called = False @@ -63,47 +76,37 @@ class TestSignal2SignalConnect(unittest.TestCase): raise TypeError("Invalid arguments") def testSignalWithoutArguments(self): - QObject.connect(self.sender, SIGNAL("destroyed()"), - self.forwarder, SIGNAL("forward()")) - QObject.connect(self.forwarder, SIGNAL("forward()"), - self.callback_noargs) + self.sender.destroyed.connect(self.forwarder.forward) + self.forwarder.forward.connect(self.callback_noargs) del self.sender # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion gc.collect() self.assertTrue(self.called) def testSignalWithOnePrimitiveTypeArgument(self): - QObject.connect(self.sender, SIGNAL("mysignal(int)"), - self.forwarder, SIGNAL("mysignal(int)")) - QObject.connect(self.forwarder, SIGNAL("mysignal(int)"), - self.callback_args) + self.sender.mysignal_int.connect(self.forwarder.mysignal_int) + self.forwarder.mysignal_int.connect(self.callback_args) self.args = (19,) - self.sender.emit(SIGNAL('mysignal(int)'), *self.args) + self.sender.mysignal_int.emit(*self.args) self.assertTrue(self.called) def testSignalWithMultiplePrimitiveTypeArguments(self): - QObject.connect(self.sender, SIGNAL("mysignal(int,int)"), - self.forwarder, SIGNAL("mysignal(int,int)")) - QObject.connect(self.forwarder, SIGNAL("mysignal(int,int)"), - self.callback_args) + self.sender.mysignal_int_int.connect(self.forwarder.mysignal_int_int) + self.forwarder.mysignal_int_int.connect(self.callback_args) self.args = (23, 29) - self.sender.emit(SIGNAL('mysignal(int,int)'), *self.args) + self.sender.mysignal_int_int.emit(*self.args) self.assertTrue(self.called) def testSignalWithOneStringArgument(self): - QObject.connect(self.sender, SIGNAL("mysignal(QString)"), - self.forwarder, SIGNAL("mysignal(QString)")) - QObject.connect(self.forwarder, SIGNAL("mysignal(QString)"), - self.callback_args) + self.sender.mysignal_string.connect(self.forwarder.mysignal_string) + self.forwarder.mysignal_string.connect(self.callback_args) self.args = ('myargument',) - self.sender.emit(SIGNAL('mysignal(QString)'), *self.args) + self.sender.mysignal_string.emit(*self.args) self.assertTrue(self.called) def testSignalWithOneQObjectArgument(self): - QObject.connect(self.sender, SIGNAL('destroyed(QObject*)'), - self.forwarder, SIGNAL('forward(QObject*)')) - QObject.connect(self.forwarder, SIGNAL('forward(QObject*)'), - self.callback_qobject) + self.sender.destroyed.connect(self.forwarder.forward_qobject) + self.forwarder.forward_qobject.connect(self.callback_qobject) obj_name = 'sender' self.sender.setObjectName(obj_name) diff --git a/sources/pyside6/tests/signals/signal_connectiontype_support_test.py b/sources/pyside6/tests/signals/signal_connectiontype_support_test.py index 95ce1fa4f..0a69c1e02 100644 --- a/sources/pyside6/tests/signals/signal_connectiontype_support_test.py +++ b/sources/pyside6/tests/signals/signal_connectiontype_support_test.py @@ -10,13 +10,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, Qt +from PySide6.QtCore import QObject, Signal, Qt -class Dummy(QObject): +class Sender(QObject): """Dummy class used in this test.""" + + foo = Signal() + def __init__(self, parent=None): - QObject.__init__(self, parent) + super().__init__(parent) class TestConnectionTypeSupport(unittest.TestCase): @@ -26,11 +29,11 @@ class TestConnectionTypeSupport(unittest.TestCase): def testNoArgs(self): """Connect signal using a Qt.ConnectionType as argument""" - obj1 = Dummy() + obj1 = Sender() - QObject.connect(obj1, SIGNAL('foo()'), self.callback, Qt.DirectConnection) + obj1.foo.connect(self.callback, Qt.DirectConnection) self.args = tuple() - obj1.emit(SIGNAL('foo()'), *self.args) + obj1.foo.emit(*self.args) self.assertTrue(self.called) diff --git a/sources/pyside6/tests/signals/signal_emission_gui_test.py b/sources/pyside6/tests/signals/signal_emission_gui_test.py index 10b5946ef..5a49b9d12 100644 --- a/sources/pyside6/tests/signals/signal_emission_gui_test.py +++ b/sources/pyside6/tests/signals/signal_emission_gui_test.py @@ -14,112 +14,104 @@ 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 SIGNAL - -try: - from PySide6.QtWidgets import QSpinBox, QPushButton - hasQtGui = True -except ImportError: - hasQtGui = False +from PySide6.QtWidgets import QSpinBox, QPushButton from helper.basicpyslotcase import BasicPySlotCase from helper.usesqapplication import UsesQApplication -if hasQtGui: - class ButtonPySlot(UsesQApplication, BasicPySlotCase): - """Tests the connection of python slots to QPushButton signals""" - - def testButtonClicked(self): - """Connection of a python slot to QPushButton.clicked()""" - button = QPushButton('Mylabel') - button.clicked.connect(self.cb) - self.args = tuple() - button.emit(SIGNAL('clicked(bool)'), False) - self.assertTrue(self.called) - - def testButtonClick(self): - """Indirect qt signal emission using the QPushButton.click() method """ - button = QPushButton('label') - button.clicked.connect(self.cb) - self.args = tuple() - button.click() - self.assertTrue(self.called) - - -if hasQtGui: - class SpinBoxPySlot(UsesQApplication, BasicPySlotCase): - """Tests the connection of python slots to QSpinBox signals""" - - def setUp(self): - super(SpinBoxPySlot, self).setUp() - self.spin = QSpinBox() - - def tearDown(self): - del self.spin - # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion - gc.collect() - super(SpinBoxPySlot, self).tearDown() - - def testSpinBoxValueChanged(self): - """Connection of a python slot to QSpinBox.valueChanged(int)""" - self.spin.valueChanged.connect(self.cb) - self.args = [3] - self.spin.emit(SIGNAL('valueChanged(int)'), *self.args) - self.assertTrue(self.called) - - def testSpinBoxValueChangedImplicit(self): - """Indirect qt signal emission using QSpinBox.setValue(int)""" - self.spin.valueChanged.connect(self.cb) - self.args = [42] - self.spin.setValue(self.args[0]) - self.assertTrue(self.called) - - def atestSpinBoxValueChangedFewArgs(self): - """Emission of signals with fewer arguments than needed""" - # XXX: PyQt4 crashes on the assertRaises - self.spin.valueChanged.connect(self.cb) - self.args = (554,) - self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)')) - -if hasQtGui: - class QSpinBoxQtSlots(UsesQApplication): - """Tests the connection to QSpinBox qt slots""" - - qapplication = True - - def testSetValueIndirect(self): - """Indirect signal emission: QSpinBox using valueChanged(int)/setValue(int)""" - spinSend = QSpinBox() - spinRec = QSpinBox() - - spinRec.setValue(5) - - spinSend.valueChanged.connect(spinRec.setValue) - self.assertEqual(spinRec.value(), 5) - spinSend.setValue(3) - self.assertEqual(spinRec.value(), 3) - self.assertEqual(spinSend.value(), 3) - - def testSetValue(self): - """Direct signal emission: QSpinBox using valueChanged(int)/setValue(int)""" - spinSend = QSpinBox() - spinRec = QSpinBox() - - spinRec.setValue(5) - spinSend.setValue(42) - - spinSend.valueChanged.connect(spinRec.setValue) - self.assertEqual(spinRec.value(), 5) - self.assertEqual(spinSend.value(), 42) - spinSend.emit(SIGNAL('valueChanged(int)'), 3) - - self.assertEqual(spinRec.value(), 3) - # Direct emission shouldn't change the value of the emitter - self.assertEqual(spinSend.value(), 42) - - spinSend.emit(SIGNAL('valueChanged(int)'), 66) - self.assertEqual(spinRec.value(), 66) - self.assertEqual(spinSend.value(), 42) + +class ButtonPySlot(UsesQApplication, BasicPySlotCase): + """Tests the connection of python slots to QPushButton signals""" + + def testButtonClicked(self): + """Connection of a python slot to QPushButton.clicked()""" + button = QPushButton('Mylabel') + button.clicked.connect(self.cb) + self.args = tuple() + button.clicked.emit() + self.assertTrue(self.called) + + def testButtonClick(self): + """Indirect qt signal emission using the QPushButton.click() method """ + button = QPushButton('label') + button.clicked.connect(self.cb) + self.args = tuple() + button.click() + self.assertTrue(self.called) + + +class SpinBoxPySlot(UsesQApplication, BasicPySlotCase): + """Tests the connection of python slots to QSpinBox signals""" + + def setUp(self): + super(SpinBoxPySlot, self).setUp() + self.spin = QSpinBox() + + def tearDown(self): + del self.spin + # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion + gc.collect() + super(SpinBoxPySlot, self).tearDown() + + def testSpinBoxValueChanged(self): + """Connection of a python slot to QSpinBox.valueChanged(int)""" + self.spin.valueChanged.connect(self.cb) + self.args = [3] + self.spin.valueChanged.emit(*self.args) + self.assertTrue(self.called) + + def testSpinBoxValueChangedImplicit(self): + """Indirect qt signal emission using QSpinBox.setValue(int)""" + self.spin.valueChanged.connect(self.cb) + self.args = [42] + self.spin.setValue(self.args[0]) + self.assertTrue(self.called) + + def atestSpinBoxValueChangedFewArgs(self): + """Emission of signals with fewer arguments than needed""" + self.spin.valueChanged.connect(self.cb) + self.args = (554,) + self.assertRaises(TypeError, self.spin.valueChanged.emit) + + +class QSpinBoxQtSlots(UsesQApplication): + """Tests the connection to QSpinBox qt slots""" + + qapplication = True + + def testSetValueIndirect(self): + """Indirect signal emission: QSpinBox using valueChanged(int)/setValue(int)""" + spinSend = QSpinBox() + spinRec = QSpinBox() + + spinRec.setValue(5) + + spinSend.valueChanged.connect(spinRec.setValue) + self.assertEqual(spinRec.value(), 5) + spinSend.setValue(3) + self.assertEqual(spinRec.value(), 3) + self.assertEqual(spinSend.value(), 3) + + def testSetValue(self): + """Direct signal emission: QSpinBox using valueChanged(int)/setValue(int)""" + spinSend = QSpinBox() + spinRec = QSpinBox() + + spinRec.setValue(5) + spinSend.setValue(42) + + spinSend.valueChanged.connect(spinRec.setValue) + self.assertEqual(spinRec.value(), 5) + self.assertEqual(spinSend.value(), 42) + spinSend.valueChanged.emit(3) + + self.assertEqual(spinRec.value(), 3) + # Direct emission shouldn't change the value of the emitter + self.assertEqual(spinSend.value(), 42) + + spinSend.valueChanged.emit(66) + self.assertEqual(spinRec.value(), 66) + self.assertEqual(spinSend.value(), 42) if __name__ == '__main__': diff --git a/sources/pyside6/tests/signals/signal_emission_test.py b/sources/pyside6/tests/signals/signal_emission_test.py index 90cce86c4..b31d89c2f 100644 --- a/sources/pyside6/tests/signals/signal_emission_test.py +++ b/sources/pyside6/tests/signals/signal_emission_test.py @@ -14,7 +14,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, QProcess, QTimeLine +from PySide6.QtCore import QObject, Signal, SIGNAL, QProcess, QTimeLine from helper.usesqapplication import UsesQApplication @@ -25,7 +25,7 @@ class ArgsOnEmptySignal(UsesQApplication): def testArgsToNoArgsSignal(self): '''Passing arguments to a signal without arguments''' process = QProcess() - self.assertRaises(TypeError, process.emit, SIGNAL('started()'), 42) + self.assertRaises(TypeError, process.started.emit, 42) class MoreArgsOnEmit(UsesQApplication): @@ -34,12 +34,14 @@ class MoreArgsOnEmit(UsesQApplication): def testMoreArgs(self): '''Passing more arguments than needed''' process = QProcess() - self.assertRaises(TypeError, process.emit, SIGNAL('finished(int)'), 55, 55) + self.assertRaises(TypeError, process.finished.emit, 55, QProcess.ExitStatus.NormalExit, 42) -class Dummy(QObject): - '''Dummy class''' - pass +class Sender(QObject): + '''Sender class''' + + dummy = Signal() + dummy_int = Signal(int) class PythonSignalToCppSlots(UsesQApplication): @@ -48,12 +50,11 @@ class PythonSignalToCppSlots(UsesQApplication): def testWithoutArgs(self): '''Connect python signal to QTimeLine.toggleDirection()''' timeline = QTimeLine() - dummy = Dummy() - QObject.connect(dummy, SIGNAL('dummy()'), - timeline, SLOT('toggleDirection()')) + sender = Sender() + sender.dummy.connect(timeline.toggleDirection) orig_dir = timeline.direction() - dummy.emit(SIGNAL('dummy()')) + sender.dummy.emit() new_dir = timeline.direction() if orig_dir == QTimeLine.Forward: @@ -64,13 +65,12 @@ class PythonSignalToCppSlots(UsesQApplication): def testWithArgs(self): '''Connect python signals to QTimeLine.setCurrentTime(int)''' timeline = QTimeLine() - dummy = Dummy() + sender = Sender() - QObject.connect(dummy, SIGNAL('dummy(int)'), - timeline, SLOT('setCurrentTime(int)')) + sender.dummy_int.connect(timeline.setCurrentTime) current = timeline.currentTime() - dummy.emit(SIGNAL('dummy(int)'), current + 42) + sender.dummy_int.emit(current + 42) self.assertEqual(timeline.currentTime(), current + 42) @@ -82,13 +82,13 @@ class CppSignalsToCppSlots(UsesQApplication): process = QProcess() timeline = QTimeLine() - QObject.connect(process, SIGNAL('finished(int, QProcess::ExitStatus)'), - timeline, SLOT('toggleDirection()')) + process.finished.connect(timeline.toggleDirection) orig_dir = timeline.direction() process.start(sys.executable, ['-c', '"print 42"']) - process.waitForFinished() + self.assertTrue(process.waitForStarted()) + self.assertTrue(process.waitForFinished()) new_dir = timeline.direction() @@ -111,9 +111,9 @@ class DynamicSignalsToFuncPartial(UsesQApplication): def testIt(self): global called called = False - o = QObject() - o.connect(o, SIGNAL("ASignal()"), functools.partial(someSlot, "partial ..")) - o.emit(SIGNAL("ASignal()")) + o = Sender() + o.dummy.connect(functools.partial(someSlot, "partial ..")) + o.dummy.emit() self.assertTrue(called) diff --git a/sources/pyside6/tests/signals/signal_manager_refcount_test.py b/sources/pyside6/tests/signals/signal_manager_refcount_test.py index 1ca1ea55f..955d5b65b 100644 --- a/sources/pyside6/tests/signals/signal_manager_refcount_test.py +++ b/sources/pyside6/tests/signals/signal_manager_refcount_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 +from PySide6.QtCore import QObject class SignalManagerRefCount(unittest.TestCase): @@ -28,7 +28,7 @@ class SignalManagerRefCount(unittest.TestCase): refcount = sys.getrefcount(obj) obj.destroyed.connect(callback) self.assertEqual(refcount, sys.getrefcount(obj)) - QObject.disconnect(obj, SIGNAL('destroyed()'), callback) + obj.destroyed.disconnect(callback) self.assertEqual(refcount, sys.getrefcount(obj)) diff --git a/sources/pyside6/tests/signals/signal_signature_test.py b/sources/pyside6/tests/signals/signal_signature_test.py index a7be1ff11..e8f08b2d9 100644 --- a/sources/pyside6/tests/signals/signal_signature_test.py +++ b/sources/pyside6/tests/signals/signal_signature_test.py @@ -20,6 +20,10 @@ called = False name = "Old" +class Sender(QObject): + dummySignal = Signal() + + class Obj(QObject): dummySignalArgs = Signal(str) numberSignal = Signal(int) @@ -78,9 +82,9 @@ class TestConnectNotifyWithNewStyleSignals(UsesQApplication): def testStaticSlot(self): global called - sender = Obj() - sender.connect(sender, SIGNAL("dummySignal()"), Obj.static_method) - sender.emit(SIGNAL("dummySignal()")) + sender = Sender() + sender.dummySignal.connect(Obj.static_method) + sender.dummySignal.emit() self.assertTrue(called) def testStaticSlotArgs(self): diff --git a/sources/pyside6/tests/signals/slot_reference_count_test.py b/sources/pyside6/tests/signals/slot_reference_count_test.py index e601590a3..9d5c73652 100644 --- a/sources/pyside6/tests/signals/slot_reference_count_test.py +++ b/sources/pyside6/tests/signals/slot_reference_count_test.py @@ -12,12 +12,14 @@ 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 +from PySide6.QtCore import QObject, Signal class Dummy(QObject): + foo = Signal() + def dispatch(self): - self.emit(SIGNAL('foo()')) + self.foo.emit() class PythonSignalRefCount(unittest.TestCase): @@ -35,10 +37,10 @@ class PythonSignalRefCount(unittest.TestCase): self.assertEqual(sys.getrefcount(cb), 2) - QObject.connect(self.emitter, SIGNAL('foo()'), cb) + self.emitter.foo.connect(cb) self.assertEqual(sys.getrefcount(cb), 3) - QObject.disconnect(self.emitter, SIGNAL('foo()'), cb) + self.emitter.foo.disconnect(cb) self.assertEqual(sys.getrefcount(cb), 2) @@ -60,7 +62,7 @@ class CppSignalRefCount(unittest.TestCase): self.emitter.destroyed.connect(cb) self.assertEqual(sys.getrefcount(cb), 3) - QObject.disconnect(self.emitter, SIGNAL('destroyed()'), cb) + self.emitter.destroyed.disconnect(cb) self.assertEqual(sys.getrefcount(cb), 2) diff --git a/sources/pyside6/tests/signals/static_metaobject_test.py b/sources/pyside6/tests/signals/static_metaobject_test.py index 6b1372d54..d7bf73e44 100644 --- a/sources/pyside6/tests/signals/static_metaobject_test.py +++ b/sources/pyside6/tests/signals/static_metaobject_test.py @@ -14,13 +14,22 @@ 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, Slot, SIGNAL from helper.usesqapplication import UsesQApplication +class Sender(QObject): + + foo = Signal() + foo2 = Signal() + + class MyObject(QObject): + + foo2 = Signal() + def __init__(self, parent=None): - QObject.__init__(self, parent) + super().__init__(parent) self._slotCalledCount = 0 # this '@Slot()' is needed to get the right sort order in testSharedSignalEmission. @@ -33,7 +42,8 @@ class MyObject(QObject): class StaticMetaObjectTest(UsesQApplication): def testSignalPropagation(self): - o = MyObject() + """Old style, dynamic signal creation.""" + o = QObject() o2 = MyObject() # SIGNAL foo not created yet @@ -55,17 +65,17 @@ class StaticMetaObjectTest(UsesQApplication): self.assertEqual(o.metaObject().indexOfSignal("foo()"), -1) def testSharedSignalEmission(self): - o = QObject() + o = Sender() m = MyObject() - o.connect(SIGNAL("foo2()"), m.mySlot) - m.connect(SIGNAL("foo2()"), m.mySlot) - o.emit(SIGNAL("foo2()")) + o.foo2.connect(m.mySlot) + m.foo2.connect(m.mySlot) + o.foo2.emit() self.assertEqual(m._slotCalledCount, 1) del o # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion gc.collect() - m.emit(SIGNAL("foo2()")) + m.foo2.emit() self.assertEqual(m._slotCalledCount, 2) |
