Split signal tests into gui and core tests
Can't use a QApplication and a QCoreApplication in the same process
This commit is contained in:
parent
359c973b42
commit
33c837a48d
7 changed files with 224 additions and 168 deletions
38
tests/signals/lambda_gui_test.py
Normal file
38
tests/signals/lambda_gui_test.py
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
|
||||||
|
'''Connecting lambda to gui signals'''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PySide.QtGui import QSpinBox, QPushButton
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from helper import UsesQApplication
|
||||||
|
from helper import decorators
|
||||||
|
|
||||||
|
|
||||||
|
@decorators.requires('PySide.QtGui')
|
||||||
|
class QtGuiSigLambda(UsesQApplication):
|
||||||
|
|
||||||
|
def testButton(self):
|
||||||
|
#Connecting a lambda to a QPushButton.clicked()
|
||||||
|
obj = QPushButton('label')
|
||||||
|
QObject.connect(obj, SIGNAL('clicked()'),
|
||||||
|
lambda: setattr(obj, 'called', True))
|
||||||
|
obj.click()
|
||||||
|
self.assert_(obj.called)
|
||||||
|
|
||||||
|
def testSpinButton(self):
|
||||||
|
#Connecting a lambda to a QPushButton.clicked()
|
||||||
|
obj = QSpinBox()
|
||||||
|
arg = 444
|
||||||
|
QObject.connect(obj, SIGNAL('valueChanged(int)'),
|
||||||
|
lambda x: setattr(obj, 'arg', 444))
|
||||||
|
obj.setValue(444)
|
||||||
|
self.assertEqual(obj.arg, arg)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -7,15 +7,7 @@ import unittest
|
||||||
|
|
||||||
from PySide.QtCore import QObject, SIGNAL, QProcess
|
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||||
|
|
||||||
try:
|
from helper import UsesQCoreApplication
|
||||||
from PySide.QtGui import QApplication, QSpinBox, QPushButton
|
|
||||||
except ImportError:
|
|
||||||
QApplication = object
|
|
||||||
QSpinBox = object
|
|
||||||
QPushButton = object
|
|
||||||
|
|
||||||
from helper import UsesQApplication, UsesQCoreApplication
|
|
||||||
from helper import decorators
|
|
||||||
|
|
||||||
|
|
||||||
class Dummy(QObject):
|
class Dummy(QObject):
|
||||||
|
|
@ -69,25 +61,5 @@ class QtSigLambda(UsesQCoreApplication):
|
||||||
self.assertEqual(dummy.called, proc.exitCode())
|
self.assertEqual(dummy.called, proc.exitCode())
|
||||||
|
|
||||||
|
|
||||||
@decorators.requires('PySide.QtGui')
|
|
||||||
class QtGuiSigLambda(UsesQApplication):
|
|
||||||
|
|
||||||
def testButton(self):
|
|
||||||
#Connecting a lambda to a QPushButton.clicked()
|
|
||||||
obj = QPushButton('label')
|
|
||||||
QObject.connect(obj, SIGNAL('clicked()'),
|
|
||||||
lambda: setattr(obj, 'called', True))
|
|
||||||
obj.click()
|
|
||||||
self.assert_(obj.called)
|
|
||||||
|
|
||||||
def testSpinButton(self):
|
|
||||||
#Connecting a lambda to a QPushButton.clicked()
|
|
||||||
obj = QSpinBox()
|
|
||||||
arg = 444
|
|
||||||
QObject.connect(obj, SIGNAL('valueChanged(int)'),
|
|
||||||
lambda x: setattr(obj, 'arg', 444))
|
|
||||||
obj.setValue(444)
|
|
||||||
self.assertEqual(obj.arg, arg)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
68
tests/signals/multiple_connections_gui_test.py
Normal file
68
tests/signals/multiple_connections_gui_test.py
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
import unittest
|
||||||
|
import random
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PySide.QtGui import QPushButton, QSpinBox
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from helper import BasicPySlotCase, UsesQApplication
|
||||||
|
from helper.decorators import requires
|
||||||
|
|
||||||
|
|
||||||
|
def random_gen(count=100, largest=99, lowest=0):
|
||||||
|
for i in range(count):
|
||||||
|
yield random.randint(lowest, largest)
|
||||||
|
|
||||||
|
|
||||||
|
class MultipleSignalConnections(unittest.TestCase):
|
||||||
|
'''Base class for multiple signal connection testing'''
|
||||||
|
|
||||||
|
def run_many(self, sender, 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
|
||||||
|
emitter - the callable that will trigger the signal
|
||||||
|
receivers - list of BasicPySlotCase instances
|
||||||
|
args - tuple with the arguments to be sent.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if args is None:
|
||||||
|
args = tuple()
|
||||||
|
|
||||||
|
for rec in receivers:
|
||||||
|
rec.setUp()
|
||||||
|
QObject.connect(sender, SIGNAL(signal), rec.cb)
|
||||||
|
rec.args = tuple(args)
|
||||||
|
|
||||||
|
emitter(*args)
|
||||||
|
|
||||||
|
for rec in receivers:
|
||||||
|
self.assert_(rec.called)
|
||||||
|
|
||||||
|
|
||||||
|
@requires('PySide.QtGui')
|
||||||
|
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)"""
|
||||||
|
for test in random_gen(10):
|
||||||
|
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, (test,))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -6,13 +6,7 @@ from functools import partial
|
||||||
|
|
||||||
from PySide.QtCore import QObject, SIGNAL, QProcess
|
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||||
|
|
||||||
try:
|
from helper import BasicPySlotCase, UsesQCoreApplication
|
||||||
from PySide.QtGui import QPushButton, QSpinBox
|
|
||||||
except ImportError:
|
|
||||||
QPushButton = object
|
|
||||||
QSpinBox = object
|
|
||||||
|
|
||||||
from helper import BasicPySlotCase, UsesQApplication, UsesQCoreApplication
|
|
||||||
from helper.decorators import requires
|
from helper.decorators import requires
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -47,26 +41,6 @@ class MultipleSignalConnections(unittest.TestCase):
|
||||||
self.assert_(rec.called)
|
self.assert_(rec.called)
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
|
||||||
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)"""
|
|
||||||
for test in random_gen(10):
|
|
||||||
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, (test,))
|
|
||||||
|
|
||||||
|
|
||||||
class PythonMultipleSlots(UsesQCoreApplication, MultipleSignalConnections):
|
class PythonMultipleSlots(UsesQCoreApplication, MultipleSignalConnections):
|
||||||
'''Multiple connections to python signals'''
|
'''Multiple connections to python signals'''
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
||||||
except ImportError:
|
except ImportError:
|
||||||
QSpinBox = object
|
pass
|
||||||
QApplication = object
|
|
||||||
QWidget = object
|
|
||||||
|
|
||||||
from helper import UsesQApplication
|
from helper import UsesQApplication
|
||||||
from helper.decorators import requires
|
from helper.decorators import requires
|
||||||
|
|
|
||||||
113
tests/signals/signal_emission_gui_test.py
Normal file
113
tests/signals/signal_emission_gui_test.py
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
"""Tests covering signal emission and receiving to python slots"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PySide.QtCore import QObject, SIGNAL, SLOT
|
||||||
|
|
||||||
|
try:
|
||||||
|
from PySide.QtGui import QSpinBox, QPushButton
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
from helper import BasicPySlotCase, UsesQApplication
|
||||||
|
from helper.decorators import requires
|
||||||
|
|
||||||
|
@requires('PySide.QtGui')
|
||||||
|
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')
|
||||||
|
QObject.connect(button, SIGNAL('clicked()'), self.cb)
|
||||||
|
self.args = tuple()
|
||||||
|
button.emit(SIGNAL('clicked()'))
|
||||||
|
self.assert_(self.called)
|
||||||
|
|
||||||
|
def testButtonClick(self):
|
||||||
|
"""Indirect qt signal emission using the QPushButton.click() method """
|
||||||
|
button = QPushButton('label')
|
||||||
|
QObject.connect(button, SIGNAL('clicked()'), self.cb)
|
||||||
|
self.args = tuple()
|
||||||
|
button.click()
|
||||||
|
self.assert_(self.called)
|
||||||
|
|
||||||
|
|
||||||
|
@requires('PySide.QtGui')
|
||||||
|
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
|
||||||
|
super(SpinBoxPySlot, self).tearDown()
|
||||||
|
|
||||||
|
def testSpinBoxValueChanged(self):
|
||||||
|
"""Connection of a python slot to QSpinBox.valueChanged(int)"""
|
||||||
|
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
||||||
|
self.args = [3]
|
||||||
|
self.spin.emit(SIGNAL('valueChanged(int)'), *self.args)
|
||||||
|
self.assert_(self.called)
|
||||||
|
|
||||||
|
def testSpinBoxValueChangedImplicit(self):
|
||||||
|
"""Indirect qt signal emission using QSpinBox.setValue(int)"""
|
||||||
|
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
||||||
|
self.args = [42]
|
||||||
|
self.spin.setValue(self.args[0])
|
||||||
|
self.assert_(self.called)
|
||||||
|
|
||||||
|
def atestSpinBoxValueChangedFewArgs(self):
|
||||||
|
"""Emission of signals with fewer arguments than needed"""
|
||||||
|
# XXX: PyQt4 crashes on the assertRaises
|
||||||
|
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
||||||
|
self.args = (554,)
|
||||||
|
self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
|
||||||
|
|
||||||
|
@requires('PySide.QtGui')
|
||||||
|
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)
|
||||||
|
|
||||||
|
QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)'))
|
||||||
|
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)
|
||||||
|
|
||||||
|
QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)'))
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
@ -8,115 +8,7 @@ import unittest
|
||||||
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
|
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
|
||||||
from PySide.QtCore import QTimer, QThread
|
from PySide.QtCore import QTimer, QThread
|
||||||
|
|
||||||
try:
|
from helper import BasicPySlotCase, UsesQCoreApplication
|
||||||
from PySide.QtGui import QSpinBox, QPushButton
|
|
||||||
except ImportError:
|
|
||||||
QSpinBox = object
|
|
||||||
QPushButton = object
|
|
||||||
QApplication = object
|
|
||||||
|
|
||||||
from helper import BasicPySlotCase, UsesQApplication, UsesQCoreApplication
|
|
||||||
from helper.decorators import requires
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
|
||||||
class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
|
||||||
"""Tests the connection of python slots to QPushButton signals"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(ButtonPySlot, self).setUp()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
super(ButtonPySlot, self).setUp()
|
|
||||||
|
|
||||||
def testButtonClicked(self):
|
|
||||||
"""Connection of a python slot to QPushButton.clicked()"""
|
|
||||||
button = QPushButton('Mylabel')
|
|
||||||
QObject.connect(button, SIGNAL('clicked()'), self.cb)
|
|
||||||
self.args = tuple()
|
|
||||||
button.emit(SIGNAL('clicked()'))
|
|
||||||
self.assert_(self.called)
|
|
||||||
|
|
||||||
def testButtonClick(self):
|
|
||||||
"""Indirect qt signal emission using the QPushButton.click() method """
|
|
||||||
button = QPushButton('label')
|
|
||||||
QObject.connect(button, SIGNAL('clicked()'), self.cb)
|
|
||||||
self.args = tuple()
|
|
||||||
button.click()
|
|
||||||
self.assert_(self.called)
|
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
|
||||||
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
|
|
||||||
super(SpinBoxPySlot, self).tearDown()
|
|
||||||
|
|
||||||
def testSpinBoxValueChanged(self):
|
|
||||||
"""Connection of a python slot to QSpinBox.valueChanged(int)"""
|
|
||||||
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
|
||||||
self.args = [3]
|
|
||||||
self.spin.emit(SIGNAL('valueChanged(int)'), *self.args)
|
|
||||||
self.assert_(self.called)
|
|
||||||
|
|
||||||
def testSpinBoxValueChangedImplicit(self):
|
|
||||||
"""Indirect qt signal emission using QSpinBox.setValue(int)"""
|
|
||||||
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
|
||||||
self.args = [42]
|
|
||||||
self.spin.setValue(self.args[0])
|
|
||||||
self.assert_(self.called)
|
|
||||||
|
|
||||||
def atestSpinBoxValueChangedFewArgs(self):
|
|
||||||
"""Emission of signals with fewer arguments than needed"""
|
|
||||||
# XXX: PyQt4 crashes on the assertRaises
|
|
||||||
QObject.connect(self.spin, SIGNAL('valueChanged(int)'), self.cb)
|
|
||||||
self.args = (554,)
|
|
||||||
self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
|
||||||
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)
|
|
||||||
|
|
||||||
QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)'))
|
|
||||||
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)
|
|
||||||
|
|
||||||
QObject.connect(spinSend, SIGNAL('valueChanged(int)'), spinRec, SLOT('setValue(int)'))
|
|
||||||
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 ArgsOnEmptySignal(UsesQCoreApplication):
|
class ArgsOnEmptySignal(UsesQCoreApplication):
|
||||||
|
|
@ -191,6 +83,7 @@ class CppSignalsToCppSlots(UsesQCoreApplication):
|
||||||
|
|
||||||
thread.start()
|
thread.start()
|
||||||
self.app.exec_()
|
self.app.exec_()
|
||||||
|
thread.exit(0)
|
||||||
thread.wait()
|
thread.wait()
|
||||||
|
|
||||||
new_dir = timeline.direction()
|
new_dir = timeline.direction()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue