Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Joe Gregorio | fe695fb | 2010-08-30 12:04:04 -0400 | [diff] [blame] | 2 | import glob |
| 3 | import logging |
| 4 | import os |
| 5 | import sys |
| 6 | import unittest |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 7 | |
| 8 | from trace import fullmodname |
| 9 | try: |
| 10 | from tests.utils import cleanup |
| 11 | except: |
| 12 | def cleanup(): |
| 13 | pass |
| 14 | |
| 15 | sys.path.insert(0, os.getcwd()) |
| 16 | |
Joe Gregorio | fe695fb | 2010-08-30 12:04:04 -0400 | [diff] [blame] | 17 | verbosity = 1 |
| 18 | if "-q" in sys.argv or '--quiet' in sys.argv: |
| 19 | verbosity = 0 |
| 20 | if "-v" in sys.argv or '--verbose' in sys.argv: |
| 21 | verbosity = 2 |
| 22 | |
| 23 | if verbosity == 0: |
| 24 | logging.disable(logging.CRITICAL) |
| 25 | elif verbosity == 1: |
| 26 | logging.disable(logging.ERROR) |
| 27 | elif verbosity == 2: |
| 28 | logging.basicConfig(level=logging.DEBUG) |
| 29 | |
| 30 | |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 31 | def build_suite(folder): |
| 32 | # find all of the test modules |
| 33 | modules = map(fullmodname, glob.glob(os.path.join(folder, 'test_*.py'))) |
Joe Gregorio | db849af | 2010-09-22 16:53:59 -0400 | [diff] [blame] | 34 | if verbosity > 0: |
| 35 | print "Running the tests found in the following modules:" |
| 36 | print modules |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 37 | |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 38 | # load all of the tests into a suite |
| 39 | try: |
| 40 | return unittest.TestLoader().loadTestsFromNames(modules) |
| 41 | except Exception, exception: |
| 42 | # attempt to produce a more specific message |
| 43 | for module in modules: |
| 44 | __import__(module) |
| 45 | raise |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 46 | |
ade@google.com | 50dce60 | 2010-09-22 17:42:53 +0100 | [diff] [blame] | 47 | # build and run unit test suite |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 48 | unit_tests = build_suite('tests') |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 49 | unittest.TextTestRunner(verbosity=verbosity).run(unit_tests) |
ade@google.com | 50dce60 | 2010-09-22 17:42:53 +0100 | [diff] [blame] | 50 | cleanup() |
| 51 | |
| 52 | # build and run functional test suite |
| 53 | functional_tests = build_suite('functional_tests') |
ade@google.com | 46179d3 | 2010-08-21 00:00:03 +0100 | [diff] [blame] | 54 | unittest.TextTestRunner(verbosity=verbosity).run(functional_tests) |
Joe Gregorio | 48d361f | 2010-08-18 13:19:21 -0400 | [diff] [blame] | 55 | cleanup() |