Adding decorator requires(ModuleName) for tests

This commit is contained in:
Lauro Neto 2009-12-15 16:04:07 -03:00
commit 859cec5632
5 changed files with 88 additions and 15 deletions

View file

@ -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)

View file

@ -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'''

View file

@ -6,14 +6,21 @@ import sys
import unittest
from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL, SLOT
from PySide.QtGui import QSpinBox, QPushButton, QApplication
from helper import BasicPySlotCase, UsesQApplication
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"""