diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2009-12-15 16:04:07 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2009-12-16 21:14:24 -0300 |
commit | 859cec5632618710821cb56eb5483f2fab290f66 (patch) | |
tree | b8fdf4c3c42a198629258cd3a40d2d4ea9e4f630 /tests/signals | |
parent | 9e6100816e6f000375d1ef2b3ec134ee7bc90fca (diff) |
Adding decorator requires(ModuleName) for tests
Diffstat (limited to 'tests/signals')
-rw-r--r-- | tests/signals/lambda_test.py | 39 | ||||
-rw-r--r-- | tests/signals/multiple_connections_test.py | 2 | ||||
-rw-r--r-- | tests/signals/signal_emission_test.py | 17 |
3 files changed, 44 insertions, 14 deletions
diff --git a/tests/signals/lambda_test.py b/tests/signals/lambda_test.py index 137a2d9a6..b9793d880 100644 --- a/tests/signals/lambda_test.py +++ b/tests/signals/lambda_test.py @@ -6,20 +6,31 @@ import sys import unittest from PySide.QtCore import QObject, SIGNAL, QProcess -from PySide.QtGui import QApplication, QSpinBox, QPushButton -from helper import UsesQApplication +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 + class Dummy(QObject): + def __init__(self, *args): super(Dummy, self).__init__(*args) + class BasicCase(unittest.TestCase): def testSimplePythonSignalNoArgs(self): #Connecting a lambda to a simple python signal without arguments obj = Dummy() - QObject.connect(obj, SIGNAL('foo()'), lambda : setattr(obj, 'called', True)) + QObject.connect(obj, SIGNAL('foo()'), + lambda: setattr(obj, 'called', True)) obj.emit(SIGNAL('foo()')) self.assert_(obj.called) @@ -27,11 +38,13 @@ class BasicCase(unittest.TestCase): #Connecting a lambda to a simple python signal witharguments obj = Dummy() arg = 42 - QObject.connect(obj, SIGNAL('foo(int)'), lambda x : setattr(obj, 'arg', 42)) + QObject.connect(obj, SIGNAL('foo(int)'), + lambda x: setattr(obj, 'arg', 42)) obj.emit(SIGNAL('foo(int)'), arg) self.assertEqual(obj.arg, arg) -class QtSigLambda(UsesQApplication): + +class QtSigLambda(UsesQCoreApplication): qapplication = True @@ -39,7 +52,8 @@ class QtSigLambda(UsesQApplication): '''Connecting a lambda to a signal without arguments''' proc = QProcess() dummy = Dummy() - QObject.connect(proc, SIGNAL('started()'), lambda : setattr(dummy, 'called', True)) + QObject.connect(proc, SIGNAL('started()'), + lambda: setattr(dummy, 'called', True)) proc.start(sys.executable, ['-c', '""']) proc.waitForFinished() self.assert_(dummy.called) @@ -48,15 +62,21 @@ class QtSigLambda(UsesQApplication): '''Connecting a lambda to a signal with arguments''' proc = QProcess() dummy = Dummy() - QObject.connect(proc, SIGNAL('finished(int)'), lambda x: setattr(dummy, 'called', x)) + QObject.connect(proc, SIGNAL('finished(int)'), + lambda x: setattr(dummy, 'called', x)) proc.start(sys.executable, ['-c', '""']) proc.waitForFinished() 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)) + QObject.connect(obj, SIGNAL('clicked()'), + lambda: setattr(obj, 'called', True)) obj.click() self.assert_(obj.called) @@ -64,7 +84,8 @@ class QtSigLambda(UsesQApplication): #Connecting a lambda to a QPushButton.clicked() obj = QSpinBox() arg = 444 - QObject.connect(obj, SIGNAL('valueChanged(int)'), lambda x: setattr(obj, 'arg', 444)) + QObject.connect(obj, SIGNAL('valueChanged(int)'), + lambda x: setattr(obj, 'arg', 444)) obj.setValue(444) self.assertEqual(obj.arg, arg) diff --git a/tests/signals/multiple_connections_test.py b/tests/signals/multiple_connections_test.py index c3ad98f70..74a139631 100644 --- a/tests/signals/multiple_connections_test.py +++ b/tests/signals/multiple_connections_test.py @@ -13,6 +13,7 @@ except ImportError: QSpinBox = object from helper import BasicPySlotCase, UsesQApplication, UsesQCoreApplication +from helper.decorators import requires def random_gen(count=100, largest=99, lowest=0): @@ -46,6 +47,7 @@ class MultipleSignalConnections(unittest.TestCase): self.assert_(rec.called) +@requires('PySide.QtGui') class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections): '''Multiple connections to QtGui signals''' diff --git a/tests/signals/signal_emission_test.py b/tests/signals/signal_emission_test.py index 8d9af620c..28e1b6582 100644 --- a/tests/signals/signal_emission_test.py +++ b/tests/signals/signal_emission_test.py @@ -6,14 +6,21 @@ import sys import unittest from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL, SLOT -from PySide.QtGui import QSpinBox, QPushButton, QApplication + +try: + from PySide.QtGui import QSpinBox, QPushButton, QApplication +except ImportError: + QSpinBox = object + QPushButton = object + QApplication = object + 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""" - qapplication = True - def setUp(self): super(ButtonPySlot, self).setUp() @@ -45,11 +52,10 @@ class ButtonPySlot(UsesQApplication, BasicPySlotCase): self.assert_(self.called) +@requires('PySide.QtGui') class SpinBoxPySlot(UsesQApplication, BasicPySlotCase): """Tests the connection of python slots to QSpinBox signals""" - qapplication = True - def setUp(self): super(SpinBoxPySlot, self).setUp() self.spin = QSpinBox() @@ -79,6 +85,7 @@ class SpinBoxPySlot(UsesQApplication, BasicPySlotCase): 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""" |