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,15 +7,14 @@ from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QSpinBox, QPushButton
|
from PySide.QtGui import QSpinBox, QPushButton
|
||||||
|
hasQtGui = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
hasQtGui = False
|
||||||
|
|
||||||
from helper import UsesQApplication
|
from helper import UsesQApplication
|
||||||
from helper import decorators
|
|
||||||
|
|
||||||
|
if hasQtGui:
|
||||||
@decorators.requires('PySide.QtGui')
|
class QtGuiSigLambda(UsesQApplication):
|
||||||
class QtGuiSigLambda(UsesQApplication):
|
|
||||||
|
|
||||||
def testButton(self):
|
def testButton(self):
|
||||||
#Connecting a lambda to a QPushButton.clicked()
|
#Connecting a lambda to a QPushButton.clicked()
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,11 @@ from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QPushButton, QSpinBox
|
from PySide.QtGui import QPushButton, QSpinBox
|
||||||
|
hasQtGui = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
hasQtGui = False
|
||||||
|
|
||||||
from helper import BasicPySlotCase, UsesQApplication
|
from helper import BasicPySlotCase, UsesQApplication
|
||||||
from helper.decorators import requires
|
|
||||||
|
|
||||||
|
|
||||||
def random_gen(count=100, largest=99, lowest=0):
|
def random_gen(count=100, largest=99, lowest=0):
|
||||||
for i in range(count):
|
for i in range(count):
|
||||||
|
|
@ -44,8 +43,8 @@ class MultipleSignalConnections(unittest.TestCase):
|
||||||
self.assert_(rec.called)
|
self.assert_(rec.called)
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
||||||
'''Multiple connections to QtGui signals'''
|
'''Multiple connections to QtGui signals'''
|
||||||
|
|
||||||
def testButtonClick(self):
|
def testButtonClick(self):
|
||||||
|
|
@ -63,6 +62,5 @@ class QtGuiMultipleSlots(UsesQApplication, MultipleSignalConnections):
|
||||||
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
self.run_many(sender, 'valueChanged(int)', sender.setValue,
|
||||||
receivers, (test,))
|
receivers, (test,))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from functools import partial
|
||||||
from PySide.QtCore import QObject, SIGNAL, QProcess
|
from PySide.QtCore import QObject, SIGNAL, QProcess
|
||||||
|
|
||||||
from helper import BasicPySlotCase, UsesQCoreApplication
|
from helper import BasicPySlotCase, UsesQCoreApplication
|
||||||
from helper.decorators import requires
|
|
||||||
|
|
||||||
|
|
||||||
def random_gen(count=50, largest=49, lowest=0):
|
def random_gen(count=50, largest=49, lowest=0):
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
from PySide.QtGui import QSpinBox, QApplication, QWidget
|
||||||
|
hasQtGui = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
hasQtGui = False
|
||||||
|
|
||||||
from helper import UsesQApplication
|
from helper import UsesQApplication
|
||||||
from helper.decorators import requires
|
|
||||||
|
|
||||||
class Dummy(QObject):
|
class Dummy(QObject):
|
||||||
"""Dummy class used in this test."""
|
"""Dummy class used in this test."""
|
||||||
|
|
@ -62,8 +62,8 @@ class PythonSigSlot(unittest.TestCase):
|
||||||
self.assert_(not self.called)
|
self.assert_(not self.called)
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class SpinBoxPySignal(UsesQApplication):
|
class SpinBoxPySignal(UsesQApplication):
|
||||||
"""Tests the connection of python signals to QSpinBox qt slots."""
|
"""Tests the connection of python signals to QSpinBox qt slots."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
@ -97,8 +97,8 @@ class SpinBoxPySignal(UsesQApplication):
|
||||||
self.assertEqual(self.spin.value(), 77)
|
self.assertEqual(self.spin.value(), 77)
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class WidgetPySignal(UsesQApplication):
|
class WidgetPySignal(UsesQApplication):
|
||||||
"""Tests the connection of python signals to QWidget qt slots."""
|
"""Tests the connection of python signals to QWidget qt slots."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,14 @@ from PySide.QtCore import QObject, SIGNAL, SLOT
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QSpinBox, QPushButton
|
from PySide.QtGui import QSpinBox, QPushButton
|
||||||
|
hasQtGui = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
hasQtGui = False
|
||||||
|
|
||||||
from helper import BasicPySlotCase, UsesQApplication
|
from helper import BasicPySlotCase, UsesQApplication
|
||||||
from helper.decorators import requires
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
||||||
"""Tests the connection of python slots to QPushButton signals"""
|
"""Tests the connection of python slots to QPushButton signals"""
|
||||||
|
|
||||||
def testButtonClicked(self):
|
def testButtonClicked(self):
|
||||||
|
|
@ -35,8 +35,8 @@ class ButtonPySlot(UsesQApplication, BasicPySlotCase):
|
||||||
self.assert_(self.called)
|
self.assert_(self.called)
|
||||||
|
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class SpinBoxPySlot(UsesQApplication, BasicPySlotCase):
|
class SpinBoxPySlot(UsesQApplication, BasicPySlotCase):
|
||||||
"""Tests the connection of python slots to QSpinBox signals"""
|
"""Tests the connection of python slots to QSpinBox signals"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
@ -68,8 +68,8 @@ class SpinBoxPySlot(UsesQApplication, BasicPySlotCase):
|
||||||
self.args = (554,)
|
self.args = (554,)
|
||||||
self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
|
self.assertRaises(TypeError, self.spin.emit, SIGNAL('valueChanged(int)'))
|
||||||
|
|
||||||
@requires('PySide.QtGui')
|
if hasQtGui:
|
||||||
class QSpinBoxQtSlots(UsesQApplication):
|
class QSpinBoxQtSlots(UsesQApplication):
|
||||||
"""Tests the connection to QSpinBox qt slots"""
|
"""Tests the connection to QSpinBox qt slots"""
|
||||||
|
|
||||||
qapplication = True
|
qapplication = True
|
||||||
|
|
|
||||||
|
|
@ -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