Fixing multiple signal tests

Changed to use a emitter argument to run_many, so we can pass
qpushbutton.click or a partial call for python signals
This commit is contained in:
Lauro Neto 2009-12-12 16:58:39 -03:00
commit 1c087643b4

View file

@ -1,6 +1,7 @@
import unittest import unittest
import random import random
from functools import partial
from PySide.QtCore import QObject, SIGNAL from PySide.QtCore import QObject, SIGNAL
from PySide.QtGui import QPushButton, QSpinBox, QApplication from PySide.QtGui import QPushButton, QSpinBox, QApplication
@ -15,10 +16,11 @@ class MultipleSignalConnections(UsesQApplication):
qapplication = True qapplication = True
def run_many(self, sender, signal, receivers, args=None): def run_many(self, sender, signal, emitter, receivers, args=None):
"""Utility method to connect a list of receivers to a signal. """Utility method to connect a list of receivers to a signal.
sender - QObject that will emit the signal sender - QObject that will emit the signal
signal - string with the signal signature signal - string with the signal signature
emitter - the callable that will trigger the signal
receivers - list of BasicPySlotCase instances receivers - list of BasicPySlotCase instances
args - tuple with the arguments to be sent. args - tuple with the arguments to be sent.
""" """
@ -31,7 +33,7 @@ class MultipleSignalConnections(UsesQApplication):
QObject.connect(sender, SIGNAL(signal), rec.cb) QObject.connect(sender, SIGNAL(signal), rec.cb)
rec.args = tuple(args) rec.args = tuple(args)
sender.emit(SIGNAL(signal), *args) emitter(*args)
for rec in receivers: for rec in receivers:
self.assert_(rec.called) self.assert_(rec.called)
@ -40,15 +42,16 @@ class MultipleSignalConnections(UsesQApplication):
"""Multiple connections to QPushButton.clicked()""" """Multiple connections to QPushButton.clicked()"""
sender = QPushButton('button') sender = QPushButton('button')
receivers = [BasicPySlotCase() for x in range(30)] receivers = [BasicPySlotCase() for x in range(30)]
self.run_many(sender, 'clicked()', receivers) self.run_many(sender, 'clicked()', sender.click, receivers)
def testSpinBoxValueChanged(self): def testSpinBoxValueChanged(self):
"""Multiple connections to QSpinBox.valueChanged(int)""" """Multiple connections to QSpinBox.valueChanged(int)"""
for test in random_gen(30): for test in random_gen(10):
sender = QSpinBox() sender = QSpinBox()
#FIXME if number of receivers if higher than 50, segfaults #FIXME if number of receivers if higher than 50, segfaults
receivers = [BasicPySlotCase() for x in range(10)] receivers = [BasicPySlotCase() for x in range(10)]
self.run_many(sender, 'valueChanged(int)', receivers, (test,)) self.run_many(sender, 'valueChanged(int)', sender.setValue,
receivers, (test,))
def testPythonSignal(self): def testPythonSignal(self):
"""Multiple connections to a python signal (short-circuit)""" """Multiple connections to a python signal (short-circuit)"""
@ -58,7 +61,8 @@ class MultipleSignalConnections(UsesQApplication):
for test in random_gen(30): for test in random_gen(30):
sender = Dummy() sender = Dummy()
receivers = [BasicPySlotCase() for x in range(10)] receivers = [BasicPySlotCase() for x in range(10)]
self.run_many(sender, 'foobar', receivers, (test, )) self.run_many(sender, 'foobar', partial(sender.emit,
SIGNAL('foobar')), receivers, (test, ))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()