aboutsummaryrefslogtreecommitdiffstats
path: root/tests/signals
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2009-12-22 20:22:53 -0300
committerLauro Neto <lauro.neto@openbossa.org>2010-01-04 20:01:48 -0300
commit33c837a48d5183bf7a6b1b4061fbb7a15d33114a (patch)
tree10346aae3b54db9b0ea6a16f2bc883775e5bd332 /tests/signals
parent359c973b425db0c27675add1a330734bbd7d8dbd (diff)
Split signal tests into gui and core tests
Can't use a QApplication and a QCoreApplication in the same process
Diffstat (limited to 'tests/signals')
-rw-r--r--tests/signals/lambda_gui_test.py38
-rw-r--r--tests/signals/lambda_test.py30
-rw-r--r--tests/signals/multiple_connections_gui_test.py68
-rw-r--r--tests/signals/multiple_connections_test.py28
-rw-r--r--tests/signals/pysignal_test.py4
-rw-r--r--tests/signals/signal_emission_gui_test.py113
-rw-r--r--tests/signals/signal_emission_test.py111
7 files changed, 224 insertions, 168 deletions
diff --git a/tests/signals/lambda_gui_test.py b/tests/signals/lambda_gui_test.py
new file mode 100644
index 000000000..b23f40bfc
--- /dev/null
+++ b/tests/signals/lambda_gui_test.py
@@ -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()
diff --git a/tests/signals/lambda_test.py b/tests/signals/lambda_test.py
index b9793d880..dff743c84 100644
--- a/tests/signals/lambda_test.py
+++ b/tests/signals/lambda_test.py
@@ -7,15 +7,7 @@ import unittest
from PySide.QtCore import QObject, SIGNAL, QProcess
-try:
- from PySide.QtGui import QApplication, QSpinBox, QPushButton
-except ImportError:
- QApplication = object
- QSpinBox = object
- QPushButton = object
-
-from helper import UsesQApplication, UsesQCoreApplication
-from helper import decorators
+from helper import UsesQCoreApplication
class Dummy(QObject):
@@ -69,25 +61,5 @@ class QtSigLambda(UsesQCoreApplication):
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__':
unittest.main()
diff --git a/tests/signals/multiple_connections_gui_test.py b/tests/signals/multiple_connections_gui_test.py
new file mode 100644
index 000000000..ba68fdb98
--- /dev/null
+++ b/tests/signals/multiple_connections_gui_test.py
@@ -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()
diff --git a/tests/signals/multiple_connections_test.py b/tests/signals/multiple_connections_test.py
index 74a139631..d2a207673 100644
--- a/tests/signals/multiple_connections_test.py
+++ b/tests/signals/multiple_connections_test.py
@@ -6,13 +6,7 @@ from functools import partial
from PySide.QtCore import QObject, SIGNAL, QProcess
-try:
- from PySide.QtGui import QPushButton, QSpinBox
-except ImportError:
- QPushButton = object
- QSpinBox = object
-
-from helper import BasicPySlotCase, UsesQApplication, UsesQCoreApplication
+from helper import BasicPySlotCase, UsesQCoreApplication
from helper.decorators import requires
@@ -47,26 +41,6 @@ class MultipleSignalConnections(unittest.TestCase):
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):
'''Multiple connections to python signals'''
diff --git a/tests/signals/pysignal_test.py b/tests/signals/pysignal_test.py
index 6409fa2c2..3d741dcca 100644
--- a/tests/signals/pysignal_test.py
+++ b/tests/signals/pysignal_test.py
@@ -5,9 +5,7 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
try:
from PySide.QtGui import QSpinBox, QApplication, QWidget
except ImportError:
- QSpinBox = object
- QApplication = object
- QWidget = object
+ pass
from helper import UsesQApplication
from helper.decorators import requires
diff --git a/tests/signals/signal_emission_gui_test.py b/tests/signals/signal_emission_gui_test.py
new file mode 100644
index 000000000..4e949e548
--- /dev/null
+++ b/tests/signals/signal_emission_gui_test.py
@@ -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()
diff --git a/tests/signals/signal_emission_test.py b/tests/signals/signal_emission_test.py
index 57b71948f..9c9f6139a 100644
--- a/tests/signals/signal_emission_test.py
+++ b/tests/signals/signal_emission_test.py
@@ -8,115 +8,7 @@ import unittest
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
from PySide.QtCore import QTimer, QThread
-try:
- 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)
+from helper import BasicPySlotCase, UsesQCoreApplication
class ArgsOnEmptySignal(UsesQCoreApplication):
@@ -191,6 +83,7 @@ class CppSignalsToCppSlots(UsesQCoreApplication):
thread.start()
self.app.exec_()
+ thread.exit(0)
thread.wait()
new_dir = timeline.direction()