OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
rmistry
2014/06/20 16:44:03
This only runs python unit tests, it should probab
borenet
2014/06/20 16:55:02
Done.
| |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Runs all unit tests under this base directory.""" | |
7 | |
8 import os | |
9 import subprocess | |
10 import sys | |
11 import unittest | |
12 | |
13 | |
14 NO_CRAWL_DIRS = [ | |
15 '.git', | |
16 '.svn', | |
17 ] | |
18 | |
19 | |
20 SEARCH_PATH = os.path.dirname(os.path.abspath(__file__)) | |
21 | |
22 | |
23 def FilterDirectory(dirpath, filenames): | |
24 """ Determine whether to look for tests in the given directory. | |
25 | |
26 dirpath: string; path of the directory in question. | |
27 filenames: list of strings; the files in the directory. | |
28 """ | |
29 if not dirpath or not filenames: | |
30 return False | |
31 for no_crawl_dir in NO_CRAWL_DIRS: | |
32 if no_crawl_dir in dirpath: | |
33 return False | |
34 return True | |
35 | |
36 | |
37 if __name__ == '__main__': | |
38 print 'Searching for tests.' | |
39 tests_to_run = [] | |
40 | |
41 for (dirpath, dirnames, filenames) in os.walk(SEARCH_PATH, topdown=True): | |
42 dirnames[:] = [d for d in dirnames if not d in NO_CRAWL_DIRS] | |
43 test_modules = [os.path.join(dirpath, filename) for filename in filenames | |
44 if filename.endswith('_test.py')] | |
45 if not test_modules: | |
46 continue | |
47 tests_to_run.extend(test_modules) | |
48 | |
49 print 'Found %d tests.' % len(tests_to_run) | |
50 errors = [] | |
51 for test in tests_to_run: | |
52 proc = subprocess.Popen(['python', test], stdout=subprocess.PIPE, | |
53 stderr=subprocess.STDOUT) | |
54 if proc.wait() != 0: | |
55 errors.append(proc.communicate()[0]) | |
56 if errors: | |
57 for error in errors: | |
58 print error | |
59 print 'Failed %d of %d.' % (len(errors), len(test_modules)) | |
60 sys.exit(1) | |
61 else: | |
62 print 'All tests succeeded.' | |
OLD | NEW |