OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Convenience script for expect_tests""" | 6 """Convenience script for expect_tests""" |
7 | 7 |
8 assert __name__ == '__main__' | 8 assert __name__ == '__main__' |
9 | 9 |
10 import itertools | 10 import itertools |
11 import os | 11 import os |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 | 14 |
15 | 15 |
16 def usage(): | 16 def usage(): |
17 print """\nUsage: %s <action> [<expect_tests options>] [<test names>] | 17 print """\nUsage: %s <action> [<test names>] [<expect_tests options>] |
pgervais
2016/04/27 16:41:16
The test/options order does not seem to matter. Is
Sergey Berezin
2016/04/27 17:32:14
It actually does now, since I need to know the lis
pgervais
2016/04/27 17:40:00
I'm afraid this is only the beginning of a long li
| |
18 | 18 |
19 where <action> is one of: list, test, train, debug. | 19 where <action> is one of: list, test, train, debug. |
20 | 20 |
21 Examples: | 21 Examples: |
22 Run all tests: | 22 Run all tests: |
23 ./test.py test | 23 ./test.py test |
24 Run all tests in the infra package: | 24 Run all tests in the infra package: |
25 ./test.py test infra | 25 ./test.py test infra --html-report /path/to/report/folder |
pgervais
2016/04/27 16:41:16
Is the --html-report option mandatory?
Sergey Berezin
2016/04/27 17:32:15
No, I just added it as an example. I'll add anothe
| |
26 Run one given test in the infra package: | 26 Run one given test in the infra package: |
27 ./test.py test infra/libs/git2/test:*testCommitBogus | 27 ./test.py test infra/libs/git2/test:*testCommitBogus |
28 | 28 |
29 See expect_tests documentation for more details | 29 See expect_tests documentation for more details |
30 """ % sys.argv[0] | 30 """ % sys.argv[0] |
31 sys.exit(1) | 31 sys.exit(1) |
32 | 32 |
33 | 33 |
34 INFRA_ROOT = os.path.dirname(os.path.abspath(__file__)) | 34 INFRA_ROOT = os.path.dirname(os.path.abspath(__file__)) |
35 | 35 |
(...skipping 26 matching lines...) Expand all Loading... | |
62 if not sys.argv[1] in ('list', 'train', 'test', 'debug'): | 62 if not sys.argv[1] in ('list', 'train', 'test', 'debug'): |
63 usage() | 63 usage() |
64 | 64 |
65 if sys.platform == 'win32': | 65 if sys.platform == 'win32': |
66 python_bin = os.path.join('ENV', 'Scripts', 'python') | 66 python_bin = os.path.join('ENV', 'Scripts', 'python') |
67 expect_tests_path = os.path.join('ENV', 'Scripts', 'expect_tests') | 67 expect_tests_path = os.path.join('ENV', 'Scripts', 'expect_tests') |
68 else: | 68 else: |
69 python_bin = os.path.join('ENV', 'bin', 'python') | 69 python_bin = os.path.join('ENV', 'bin', 'python') |
70 expect_tests_path = os.path.join('ENV', 'bin', 'expect_tests') | 70 expect_tests_path = os.path.join('ENV', 'bin', 'expect_tests') |
71 | 71 |
72 args = sys.argv[1:] | 72 command = sys.argv[1] |
73 args = sys.argv[2:] | |
74 | |
75 modules = [] | |
76 flags = [] | |
77 for arg in args: | |
78 if arg.startswith('-'): | |
79 flags.append(arg) | |
80 continue | |
81 if flags: | |
82 flags.append(arg) | |
83 else: | |
84 modules.append(arg) | |
73 | 85 |
74 # Set up default list of packages/directories if none have been provided. | 86 # Set up default list of packages/directories if none have been provided. |
75 if all([arg.startswith('--') for arg in sys.argv[2:]]): | 87 if not modules: |
76 if sys.platform == 'win32': | 88 if sys.platform == 'win32': |
77 args.extend(WIN_ENABLED_PACKAGES) | 89 modules.extend(WIN_ENABLED_PACKAGES) |
78 else: | 90 else: |
79 args.extend(['infra', 'infra_libs']) # TODO(pgervais): add 'test/' | 91 modules.extend(['infra', 'infra_libs']) # TODO(pgervais): add 'test/' |
80 appengine_dir = os.path.join(INFRA_ROOT, 'appengine') | 92 appengine_dir = os.path.join(INFRA_ROOT, 'appengine') |
81 if sys.platform != 'win32' and os.path.isdir(appengine_dir): | 93 if sys.platform != 'win32' and os.path.isdir(appengine_dir): |
82 args.extend(['appengine_module']) | 94 modules.extend(['appengine_module']) |
83 appengine_dirs = [ | 95 appengine_dirs = [ |
84 os.path.join('appengine', d) | 96 os.path.join('appengine', d) |
85 for d in os.listdir(appengine_dir) | 97 for d in os.listdir(appengine_dir) |
86 ] | 98 ] |
87 # Use relative paths to shorten the command-line | 99 # Use relative paths to shorten the command-line |
88 args.extend(itertools.chain( | 100 modules.extend(itertools.chain( |
89 [d for d in appengine_dirs if os.path.isfile(os.path.join(d, 'app.yaml'))] | 101 [d for d in appengine_dirs if os.path.isfile(os.path.join(d, 'app.yaml'))] |
90 )) | 102 )) |
91 | 103 |
92 os.environ['PYTHONPATH'] = '' | 104 os.environ['PYTHONPATH'] = '' |
93 os.chdir(INFRA_ROOT) | 105 os.chdir(INFRA_ROOT) |
94 if '--help' not in sys.argv and '-h' not in sys.argv: | 106 if '--help' not in sys.argv and '-h' not in sys.argv: |
pgervais
2016/04/27 16:41:16
'not in flags' instead?
Sergey Berezin
2016/04/27 17:32:15
Done. I also improved printing the usage info.
| |
95 subprocess.check_call( | 107 subprocess.check_call( |
96 [python_bin, os.path.join('bootstrap', 'remove_orphaned_pycs.py')]) | 108 [python_bin, os.path.join('bootstrap', 'remove_orphaned_pycs.py')]) |
97 if sys.platform == 'win32' and '--force-coverage' not in args: | 109 if sys.platform == 'win32' and '--force-coverage' not in flags: |
98 args.append('--no-coverage') | 110 flags.append('--no-coverage') |
99 sys.exit(subprocess.call([python_bin, expect_tests_path] + args)) | 111 |
112 exit_code = 0 | |
113 for module in modules: | |
114 print 'Running %s...' % module | |
115 module_flags = flags[:] | |
116 module_flags.append('--coveragerc=%s' % os.path.join( | |
117 INFRA_ROOT, module, '.coveragerc')) | |
118 module_flags.append('--html-report-subdir=%s' % module) | |
119 cmd = [python_bin, expect_tests_path] + [command] + [module] + module_flags | |
120 exit_code = max(exit_code, subprocess.call(cmd)) | |
pgervais
2016/04/27 16:41:16
'subprocess.call(cmd) or exit_code' instead
We wa
Sergey Berezin
2016/04/27 17:32:14
Done.
Also printed the list of failing modules at
| |
121 | |
122 sys.exit(exit_code) | |
OLD | NEW |