Refactored runtests.py so that it can run contrib_tests
diff --git a/runtests.py b/runtests.py
index d12b2c5..e360416 100644
--- a/runtests.py
+++ b/runtests.py
@@ -4,31 +4,19 @@
import os
import sys
import unittest
-
from trace import fullmodname
-try:
- from tests.utils import cleanup
-except:
- def cleanup():
- pass
+# Conditional import of cleanup function
+try:
+ from tests.utils import cleanup
+except:
+ def cleanup():
+ pass
+
+# Ensure current working directory is in path
sys.path.insert(0, os.getcwd())
-verbosity = 1
-if "-q" in sys.argv or '--quiet' in sys.argv:
- verbosity = 0
-if "-v" in sys.argv or '--verbose' in sys.argv:
- verbosity = 2
-
-if verbosity == 0:
- logging.disable(logging.CRITICAL)
-elif verbosity == 1:
- logging.disable(logging.ERROR)
-elif verbosity == 2:
- logging.basicConfig(level=logging.DEBUG)
-
-
-def build_suite(folder):
+def build_suite(folder, verbosity):
# find all of the test modules
modules = map(fullmodname, glob.glob(os.path.join(folder, 'test_*.py')))
if verbosity > 0:
@@ -37,19 +25,34 @@
# load all of the tests into a suite
try:
- return unittest.TestLoader().loadTestsFromNames(modules)
+ return unittest.TestLoader().loadTestsFromNames(modules)
except Exception, exception:
- # attempt to produce a more specific message
- for module in modules:
- __import__(module)
- raise
+ # attempt to produce a more specific message
+ for module in modules:
+ __import__(module)
+ raise
-# build and run unit test suite
-unit_tests = build_suite('tests')
-unittest.TextTestRunner(verbosity=verbosity).run(unit_tests)
-cleanup()
+def run(test_folder_name, verbosity=1):
+ # Build and run the tests in test_folder_name
+ tests = build_suite(test_folder_name, verbosity)
+ unittest.TextTestRunner(verbosity=verbosity).run(tests)
+ cleanup()
-# build and run functional test suite
-functional_tests = build_suite('functional_tests')
-unittest.TextTestRunner(verbosity=verbosity).run(functional_tests)
-cleanup()
+def main():
+ verbosity = 1
+ if "-q" in sys.argv or '--quiet' in sys.argv:
+ verbosity = 0
+ if "-v" in sys.argv or '--verbose' in sys.argv:
+ verbosity = 2
+ if verbosity == 0:
+ logging.disable(logging.CRITICAL)
+ elif verbosity == 1:
+ logging.disable(logging.ERROR)
+ elif verbosity == 2:
+ logging.basicConfig(level=logging.DEBUG)
+ run('tests', verbosity)
+ run('functional_tests', verbosity)
+ run('contrib_tests', verbosity)
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file