aboutsummaryrefslogtreecommitdiffstats
path: root/tests/util
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2009-12-15 16:04:07 -0300
committerLauro Neto <lauro.neto@openbossa.org>2009-12-16 21:14:24 -0300
commit859cec5632618710821cb56eb5483f2fab290f66 (patch)
treeb8fdf4c3c42a198629258cd3a40d2d4ea9e4f630 /tests/util
parent9e6100816e6f000375d1ef2b3ec134ee7bc90fca (diff)
Adding decorator requires(ModuleName) for tests
Diffstat (limited to 'tests/util')
-rw-r--r--tests/util/helper/__init__.py (renamed from tests/util/helper.py)0
-rw-r--r--tests/util/helper/decorators.py43
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/util/helper.py b/tests/util/helper/__init__.py
index a010934ae..a010934ae 100644
--- a/tests/util/helper.py
+++ b/tests/util/helper/__init__.py
diff --git a/tests/util/helper/decorators.py b/tests/util/helper/decorators.py
new file mode 100644
index 000000000..ca7f9cdaf
--- /dev/null
+++ b/tests/util/helper/decorators.py
@@ -0,0 +1,43 @@
+
+'''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