aboutsummaryrefslogtreecommitdiffstats
path: root/tests/signals
diff options
context:
space:
mode:
authorAnderson Lizardo <anderson.lizardo@openbossa.org>2010-02-25 12:25:41 -0400
committerAnderson Lizardo <anderson.lizardo@openbossa.org>2010-03-02 10:13:11 -0400
commita13b5b014569c46d9a8b5a09ac24162fada7b9f5 (patch)
treed5ad4ac66b0b1dfe921778907099aa51c3f46c4b /tests/signals
parentb10d28d07f215ae8f237f038db2a5d90009055c5 (diff)
Replace "requires" class decorator with a simple if (for Python 2.5 compatibility)
Reviewed-by: Lauro Moura <lauro.neto@openbossa.org> Reviewed-by: Bruno Araujo <bruno.araujo@openbossa.org>
Diffstat (limited to 'tests/signals')
-rw-r--r--tests/signals/lambda_gui_test.py45
-rw-r--r--tests/signals/multiple_connections_gui_test.py42
-rw-r--r--tests/signals/multiple_connections_test.py1
-rw-r--r--tests/signals/pysignal_test.py92
-rw-r--r--tests/signals/signal_emission_gui_test.py192
5 files changed, 184 insertions, 188 deletions
diff --git a/tests/signals/lambda_gui_test.py b/tests/signals/lambda_gui_test.py
index b23f40bfc..e842ae2e2 100644
--- a/tests/signals/lambda_gui_test.py
+++ b/tests/signals/lambda_gui_test.py
@@ -7,32 +7,31 @@ from PySide.QtCore import QObject, SIGNAL
try:
from PySide.QtGui import QSpinBox, QPushButton
+ hasQtGui = True
except ImportError:
- pass
+ hasQtGui = False
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 hasQtGui:
+ 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
index ba68fdb98..72feac08f 100644
--- a/tests/signals/multiple_connections_gui_test.py
+++ b/tests/signals/multiple_connections_gui_test.py
@@ -6,12 +6,11 @@ from PySide.QtCore import QObject, SIGNAL
try:
from PySide.QtGui import QPushButton, QSpinBox
+ hasQtGui = True
except ImportError:
- pass
+ hasQtGui = False
from helper import BasicPySlotCase, UsesQApplication
-from helper.decorators import requires
-
def random_gen(count=100, largest=99, lowest=0):
for i in range(count):
@@ -44,25 +43,24 @@ 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,))
-
+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)"""
+ 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 9f45f4da4..5daeaab87 100644
--- a/tests/signals/multiple_connections_test.py
+++ b/tests/signals/multiple_connections_test.py
@@ -7,7 +7,6 @@ from functools import partial
from PySide.QtCore import QObject, SIGNAL, QProcess
from helper import BasicPySlotCase, UsesQCoreApplication
-from helper.decorators import requires
def random_gen(count=50, largest=49, lowest=0):
diff --git a/tests/signals/pysignal_test.py b/tests/signals/pysignal_test.py
index 639a7dee2..5f7fc85a2 100644
--- a/tests/signals/pysignal_test.py
+++ b/tests/signals/pysignal_test.py
@@ -4,11 +4,11 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
try:
from PySide.QtGui import QSpinBox, QApplication, QWidget
+ hasQtGui = True
except ImportError:
- pass
+ hasQtGui = False
from helper import UsesQApplication
-from helper.decorators import requires
class Dummy(QObject):
"""Dummy class used in this test."""
@@ -62,64 +62,64 @@ class PythonSigSlot(unittest.TestCase):
self.assert_(not self.called)
-@requires('PySide.QtGui')
-class SpinBoxPySignal(UsesQApplication):
- """Tests the connection of python signals to QSpinBox qt slots."""
+if hasQtGui:
+ 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(SpinBoxPySignal, self).setUp()
+ self.obj = Dummy()
+ self.spin = QSpinBox()
+ self.spin.setValue(0)
- def tearDown(self):
- super(SpinBoxPySignal, self).tearDown()
- del self.obj
- del self.spin
+ def tearDown(self):
+ super(SpinBoxPySignal, self).tearDown()
+ del self.obj
+ del self.spin
- 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)
+ 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.emit(SIGNAL('dummy(int)'), 4)
- self.assertEqual(self.spin.value(), 4)
+ self.obj.emit(SIGNAL('dummy(int)'), 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)"""
+ QObject.connect(self.obj, SIGNAL('dummy(int)'), self.spin, SLOT('setValue(int)'))
+ self.assertEqual(self.spin.value(), 0)
- self.obj.emit(SIGNAL('dummy(int)'), 4)
- self.assertEqual(self.spin.value(), 4)
+ self.obj.emit(SIGNAL('dummy(int)'), 4)
+ self.assertEqual(self.spin.value(), 4)
- self.obj.emit(SIGNAL('dummy(int)'), 77)
- self.assertEqual(self.spin.value(), 77)
+ self.obj.emit(SIGNAL('dummy(int)'), 77)
+ self.assertEqual(self.spin.value(), 77)
-@requires('PySide.QtGui')
-class WidgetPySignal(UsesQApplication):
- """Tests the connection of python signals to QWidget qt slots."""
+if hasQtGui:
+ class WidgetPySignal(UsesQApplication):
+ """Tests the connection of python signals to QWidget qt slots."""
- def setUp(self):
- super(WidgetPySignal, self).setUp()
- self.obj = Dummy()
- 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
+ def tearDown(self):
+ super(WidgetPySignal, self).tearDown()
+ del self.obj
+ del self.widget
- 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()
- QObject.connect(self.obj, SIGNAL('dummy()'), self.widget, SLOT('show()'))
- self.assert_(not self.widget.isVisible())
+ QObject.connect(self.obj, SIGNAL('dummy()'), self.widget, SLOT('show()'))
+ self.assert_(not self.widget.isVisible())
- self.obj.emit(SIGNAL('dummy()'))
- self.assert_(self.widget.isVisible())
+ self.obj.emit(SIGNAL('dummy()'))
+ self.assert_(self.widget.isVisible())
if __name__ == '__main__':
unittest.main()
diff --git a/tests/signals/signal_emission_gui_test.py b/tests/signals/signal_emission_gui_test.py
index f9a6f8abd..6ae4ceb2b 100644
--- a/tests/signals/signal_emission_gui_test.py
+++ b/tests/signals/signal_emission_gui_test.py
@@ -8,105 +8,105 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
try:
from PySide.QtGui import QSpinBox, QPushButton
+ hasQtGui = True
except ImportError:
- pass
+ hasQtGui = False
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(bool)'), False)
- 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 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')
+ QObject.connect(button, SIGNAL('clicked()'), self.cb)
+ self.args = tuple()
+ button.emit(SIGNAL('clicked(bool)'), False)
+ 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)
+
+
+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
+ 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)'))
+
+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)
+
+ 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__':