OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 from __future__ import print_function | 3 from __future__ import print_function |
4 | 4 |
5 import argparse | 5 import argparse |
6 import os | 6 import os |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
9 | 9 |
10 from tools import cov | 10 from tools import cov |
11 | 11 |
12 | 12 |
13 is_python3 = bool(sys.version_info.major == 3) | |
14 has_python34 = False | |
15 verbose = False | 13 verbose = False |
| 14 |
16 repo_dir = os.path.abspath(os.path.dirname(__file__)) | 15 repo_dir = os.path.abspath(os.path.dirname(__file__)) |
17 path_to_cov = os.path.join(repo_dir, 'tools', 'cov.py') | 16 path_to_cov = os.path.join(repo_dir, 'tools', 'cov.py') |
18 path_to_runner = os.path.join(repo_dir, 'typ', 'runner.py') | 17 path_to_runner = os.path.join(repo_dir, 'typ', 'runner.py') |
19 | 18 |
20 | 19 |
21 def call(*args, **kwargs): | 20 def call(*args, **kwargs): |
22 if verbose: | 21 if verbose: |
23 print(' '.join(args[0])) | 22 print(' '.join(args[0])) |
24 ret = subprocess.call(*args, **kwargs) | 23 ret = subprocess.call(*args, **kwargs) |
25 if ret != 0: | 24 if ret != 0: |
26 sys.exit(ret) | 25 sys.exit(ret) |
27 | 26 |
28 | 27 |
29 def main(argv): | 28 def main(argv): |
30 parser = argparse.ArgumentParser(prog='run') | 29 parser = argparse.ArgumentParser(prog='run') |
31 parser.add_argument('--no3', action='store_true', | |
32 help='Do not run the tests under Python 3.') | |
33 parser.add_argument('-v', '--verbose', action='store_true') | 30 parser.add_argument('-v', '--verbose', action='store_true') |
34 subps = parser.add_subparsers() | 31 subps = parser.add_subparsers() |
35 | 32 |
36 subp = subps.add_parser('clean', help='Remove any local files.') | 33 subp = subps.add_parser('clean', help='Remove any local files.') |
37 subp.set_defaults(func=run_clean) | 34 subp.set_defaults(func=run_clean) |
38 | 35 |
39 subp = subps.add_parser('coverage', | 36 subp = subps.add_parser('coverage', |
40 help='Run the tests and report code coverage.') | 37 help='Run the tests and report code coverage.') |
41 subp.set_defaults(func=run_coverage) | 38 subp.set_defaults(func=run_coverage) |
42 cov.add_arguments(subp) | 39 cov.add_arguments(subp) |
(...skipping 10 matching lines...) Expand all Loading... |
53 | 50 |
54 subp = subps.add_parser('tests', | 51 subp = subps.add_parser('tests', |
55 help='run the tests') | 52 help='run the tests') |
56 subp.set_defaults(func=run_tests) | 53 subp.set_defaults(func=run_tests) |
57 | 54 |
58 args = parser.parse_args(argv) | 55 args = parser.parse_args(argv) |
59 | 56 |
60 global verbose | 57 global verbose |
61 if args.verbose: | 58 if args.verbose: |
62 verbose = True | 59 verbose = True |
63 global has_python34 | |
64 if not args.no3: | |
65 try: | |
66 ver = subprocess.check_output(['python3', '--version']) | |
67 has_python34 = ver.split()[1] >= '3.4' | |
68 except: | |
69 pass | |
70 args.func(args) | 60 args.func(args) |
71 | 61 |
72 | 62 |
73 def run_clean(args): | 63 def run_clean(args): |
74 call(['git', 'clean', '-fxd']) | 64 call(['git', 'clean', '-fxd']) |
75 | 65 |
76 | 66 |
77 def run_coverage(args): | 67 def run_coverage(args): |
78 if not args.path: | 68 if not args.path: |
79 args.path = [repo_dir] | 69 args.path = [repo_dir] |
80 if not args.source: | 70 if not args.source: |
81 args.source = [os.path.join(repo_dir, 'typ')] | 71 args.source = [os.path.join(repo_dir, 'typ')] |
82 argv = cov.argv_from_args(args) | 72 argv = cov.argv_from_args(args) |
83 cov_args = [path_to_runner, '-j', '1'] | 73 cov_args = [path_to_runner, '-j', '1'] |
84 print('Running coverage of unit tests for Python 2.7.') | 74 python = sys.executable |
85 call(['python', path_to_cov] + argv + cov_args) | 75 call([python, path_to_cov] + argv + cov_args) |
86 if has_python34: | |
87 print('Running coverage of unit tests for Python 3.4.') | |
88 call(['python3', path_to_cov] + argv + cov_args) | |
89 | 76 |
90 | 77 |
91 def run_help(args): | 78 def run_help(args): |
92 if args.subcommand: | 79 if args.subcommand: |
93 main([args.subcommand, '--help']) | 80 main([args.subcommand, '--help']) |
94 main(['--help']) | 81 main(['--help']) |
95 | 82 |
96 | 83 |
97 def run_lint(args): | 84 def run_lint(args): |
98 call('pylint --rcfile=pylintrc */*.py */*/*.py', shell=True) | 85 call('pylint --rcfile=pylintrc */*.py */*/*.py', shell=True) |
99 | 86 |
100 | 87 |
101 def run_tests(args): | 88 def run_tests(args): |
102 print('Testing running the typ module directly if it is in sys.path.') | 89 python = sys.executable |
103 call(['python', '-m', 'typ', 'typ.tests.main_test.TestMain.test_basic']) | 90 # Test running the typ module directly if it is in sys.path. |
| 91 call([python, '-m', 'typ', 'typ.tests.main_test.TestMain.test_basic']) |
104 | 92 |
105 print('Testing running the runner directly if nothing is in sys.path.') | 93 # Testing running the runner directly if nothing is in sys.path.' |
106 home_dir = os.environ['HOME'] | 94 home_dir = os.environ['HOME'] |
107 call(['python', path_to_runner, 'typ.tests.main_test.TestMain.test_basic'], | 95 call([python, path_to_runner, 'typ.tests.main_test.TestMain.test_basic'], |
108 cwd=home_dir) | 96 cwd=home_dir) |
109 | 97 |
110 # Now run all the tests under Python2 and Python3. | 98 # Run the remaining tests. |
111 print('Running the unit tests under Python 2.') | 99 call([python, path_to_runner]) |
112 call(['python', path_to_runner]) | |
113 if has_python34: | |
114 print('Running the unit tests under Python 3.4.') | |
115 call(['python3', path_to_runner]) | |
116 | 100 |
117 | 101 |
118 if __name__ == '__main__': | 102 if __name__ == '__main__': |
119 sys.exit(main(sys.argv[1:])) | 103 sys.exit(main(sys.argv[1:])) |
OLD | NEW |