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>
This commit is contained in:
parent
b10d28d07f
commit
a13b5b0145
6 changed files with 159 additions and 206 deletions
|
|
@ -7,14 +7,13 @@ 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')
|
||||
if hasQtGui:
|
||||
class QtGuiSigLambda(UsesQApplication):
|
||||
|
||||
def testButton(self):
|
||||
|
|
|
|||
|
|
@ -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,7 +43,7 @@ class MultipleSignalConnections(unittest.TestCase):
|
|||
self.assert_(rec.called)
|
||||
|
||||
|
||||
@requires('PySide.QtGui')
|
||||
if hasQtGui:
|
||||
class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
||||
'''Multiple connections to QtGui signals'''
|
||||
|
||||
|
|
@ -63,6 +62,5 @@ class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
|||
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
||||
receivers, (test,))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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,7 +62,7 @@ class PythonSigSlot(unittest.TestCase):
|
|||
self.assert_(not self.called)
|
||||
|
||||
|
||||
@requires('PySide.QtGui')
|
||||
if hasQtGui:
|
||||
class SpinBoxPySignal(UsesQApplication):
|
||||
"""Tests the connection of python signals to QSpinBox qt slots."""
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ class SpinBoxPySignal(UsesQApplication):
|
|||
self.assertEqual(self.spin.value(), 77)
|
||||
|
||||
|
||||
@requires('PySide.QtGui')
|
||||
if hasQtGui:
|
||||
class WidgetPySignal(UsesQApplication):
|
||||
"""Tests the connection of python signals to QWidget qt slots."""
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ 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')
|
||||
if hasQtGui:
|
||||
class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
||||
"""Tests the connection of python slots to QPushButton signals"""
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
|||
self.assert_(self.called)
|
||||
|
||||
|
||||
@requires('PySide.QtGui')
|
||||
if hasQtGui:
|
||||
class SpinBoxPySlot(UsesQApplication, BasicPySlotCase):
|
||||
"""Tests the connection of python slots to QSpinBox signals"""
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ class SpinBoxPySlot(UsesQApplication, BasicPySlotCase):
|
|||
self.args = (554,)
|
||||
self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
|
||||
|
||||
@requires('PySide.QtGui')
|
||||
if hasQtGui:
|
||||
class QSpinBoxQtSlots(UsesQApplication):
|
||||
"""Tests the connection to QSpinBox qt slots"""
|
||||
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
'''Decorators for skipping test methods and test cases'''
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
|
||||
class requires(object):
|
||||
'''Skip if the given module is not found
|
||||
|
||||
Usage:
|
||||
|
||||
@requires('RequiredModule')
|
||||
class MyTestCase(unittest.TestCase):
|
||||
...
|
||||
'''
|
||||
|
||||
def __init__(self, *args):
|
||||
'''Setup this decorator. Args should be a list of
|
||||
module names'''
|
||||
self.skip = False
|
||||
|
||||
for module in args:
|
||||
try:
|
||||
__import__(module)
|
||||
except ImportError:
|
||||
self.skip = True
|
||||
self.skipped = module
|
||||
break
|
||||
|
||||
def __call__(self, klass):
|
||||
'''Replace a skipped class with a dummy testCase'''
|
||||
if not self.skip:
|
||||
return klass
|
||||
|
||||
logging.warning('Module %s not found. Skipping %s' % (self.skipped,
|
||||
klass.__name__))
|
||||
|
||||
class SkipWrapper(unittest.TestCase):
|
||||
'''Dummy wrapper'''
|
||||
pass
|
||||
|
||||
return SkipWrapper
|
||||
Loading…
Add table
Add a link
Reference in a new issue