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