blob: d12b2c53b0b09b7a30c847a058e5e397f206b33b [file] [log] [blame]
Joe Gregorio48d361f2010-08-18 13:19:21 -04001#!/usr/bin/env python
Joe Gregoriofe695fb2010-08-30 12:04:04 -04002import glob
3import logging
4import os
5import sys
6import unittest
Joe Gregorio48d361f2010-08-18 13:19:21 -04007
8from trace import fullmodname
9try:
10 from tests.utils import cleanup
11except:
12 def cleanup():
13 pass
14
15sys.path.insert(0, os.getcwd())
16
Joe Gregoriofe695fb2010-08-30 12:04:04 -040017verbosity = 1
18if "-q" in sys.argv or '--quiet' in sys.argv:
19 verbosity = 0
20if "-v" in sys.argv or '--verbose' in sys.argv:
21 verbosity = 2
22
23if verbosity == 0:
24 logging.disable(logging.CRITICAL)
25elif verbosity == 1:
26 logging.disable(logging.ERROR)
27elif verbosity == 2:
28 logging.basicConfig(level=logging.DEBUG)
29
30
ade@google.com46179d32010-08-21 00:00:03 +010031def build_suite(folder):
32 # find all of the test modules
33 modules = map(fullmodname, glob.glob(os.path.join(folder, 'test_*.py')))
Joe Gregoriodb849af2010-09-22 16:53:59 -040034 if verbosity > 0:
35 print "Running the tests found in the following modules:"
36 print modules
Joe Gregorio48d361f2010-08-18 13:19:21 -040037
ade@google.com46179d32010-08-21 00:00:03 +010038 # 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 Gregorio48d361f2010-08-18 13:19:21 -040046
ade@google.com50dce602010-09-22 17:42:53 +010047# build and run unit test suite
ade@google.com46179d32010-08-21 00:00:03 +010048unit_tests = build_suite('tests')
ade@google.com46179d32010-08-21 00:00:03 +010049unittest.TextTestRunner(verbosity=verbosity).run(unit_tests)
ade@google.com50dce602010-09-22 17:42:53 +010050cleanup()
51
52# build and run functional test suite
53functional_tests = build_suite('functional_tests')
ade@google.com46179d32010-08-21 00:00:03 +010054unittest.TextTestRunner(verbosity=verbosity).run(functional_tests)
Joe Gregorio48d361f2010-08-18 13:19:21 -040055cleanup()