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:
Anderson Lizardo 2010-02-25 12:25:41 -04:00
commit a13b5b0145
6 changed files with 159 additions and 206 deletions

View file

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