1import os
2import sys
3import unittest
4
5gae_path = '/usr/local/google_appengine'
6
7current_path = os.path.abspath(os.path.dirname(__file__))
8tests_path = os.path.join(current_path, 'tests')
9sys.path[0:0] = [
10    current_path,
11    tests_path,
12    gae_path,
13    # All libs used by webapp2 and extras.
14    os.path.join(current_path, 'lib', 'babel'),
15    os.path.join(current_path, 'lib', 'Jinja2-2.6'),
16    os.path.join(current_path, 'lib', 'Mako-0.4.1'),
17    os.path.join(current_path, 'lib', 'gaepytz-2011h'),
18    os.path.join(current_path, 'lib', 'WebOb-1.0.8'),
19    # SDK libs.
20    os.path.join(gae_path, 'lib', 'django_0_96'),
21    #os.path.join(gae_path, 'lib', 'webob'),
22    os.path.join(gae_path, 'lib', 'yaml', 'lib'),
23    os.path.join(gae_path, 'lib', 'protorpc'),
24    os.path.join(gae_path, 'lib', 'simplejson'),
25]
26
27all_tests = [f[:-8] for f in os.listdir(tests_path) if f.endswith('_test.py')]
28
29def get_suite(tests):
30    tests = sorted(tests)
31    suite = unittest.TestSuite()
32    loader = unittest.TestLoader()
33    for test in tests:
34        suite.addTest(loader.loadTestsFromName(test))
35    return suite
36
37if __name__ == '__main__':
38    """
39    To run all tests:
40        $ python run_tests.py
41    To run a single test:
42        $ python run_tests.py app
43    To run a couple of tests:
44        $ python run_tests.py app config sessions
45    To run code coverage:
46        $ coverage run run_tests.py
47        $ coverage report -m
48    """
49    tests = sys.argv[1:]
50    if not tests:
51        tests = all_tests
52    tests = ['%s_test' % t for t in tests]
53    suite = get_suite(tests)
54    unittest.TextTestRunner(verbosity=2).run(suite)
55