3 from __future__
import print_function
13 is_python3
= bool(sys
.version_info
.major
== 3)
16 repo_dir
= os
.path
.abspath(os
.path
.dirname(__file__
))
17 path_to_cov
= os
.path
.join(repo_dir
, 'tools', 'cov.py')
18 path_to_runner
= os
.path
.join(repo_dir
, 'typ', 'runner.py')
21 def call(*args
, **kwargs
):
23 print(' '.join(args
[0]))
24 ret
= subprocess
.call(*args
, **kwargs
)
30 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')
34 subps
= parser
.add_subparsers()
36 subp
= subps
.add_parser('clean', help='Remove any local files.')
37 subp
.set_defaults(func
=run_clean
)
39 subp
= subps
.add_parser('coverage',
40 help='Run the tests and report code coverage.')
41 subp
.set_defaults(func
=run_coverage
)
42 cov
.add_arguments(subp
)
44 subp
= subps
.add_parser('help',
45 help='Get help on a subcommand.')
46 subp
.add_argument(nargs
='?', action
='store', dest
='subcommand',
47 help='The command to get help for.')
48 subp
.set_defaults(func
=run_help
)
50 subp
= subps
.add_parser('lint',
51 help='run lint over the source')
52 subp
.set_defaults(func
=run_lint
)
54 subp
= subps
.add_parser('tests',
56 subp
.set_defaults(func
=run_tests
)
58 args
= parser
.parse_args(argv
)
66 ver
= subprocess
.check_output(['python3', '--version'])
67 has_python34
= ver
.split()[1] >= '3.4'
74 call(['git', 'clean', '-fxd'])
77 def run_coverage(args
):
79 args
.path
= [repo_dir
]
81 args
.source
= [os
.path
.join(repo_dir
, 'typ')]
82 argv
= cov
.argv_from_args(args
)
83 cov_args
= [path_to_runner
, '-j', '1']
84 print('Running coverage of unit tests for Python 2.7.')
85 call(['python', path_to_cov
] + argv
+ cov_args
)
87 print('Running coverage of unit tests for Python 3.4.')
88 call(['python3', path_to_cov
] + argv
+ cov_args
)
93 main([args
.subcommand
, '--help'])
98 call('pylint --rcfile=pylintrc */*.py */*/*.py', shell
=True)
102 print('Testing running the typ module directly if it is in sys.path.')
103 call(['python', '-m', 'typ', 'typ.tests.main_test.TestMain.test_basic'])
105 print('Testing running the runner directly if nothing is in sys.path.')
106 home_dir
= os
.environ
['HOME']
107 call(['python', path_to_runner
, 'typ.tests.main_test.TestMain.test_basic'],
110 # Now run all the tests under Python2 and Python3.
111 print('Running the unit tests under Python 2.')
112 call(['python', path_to_runner
])
114 print('Running the unit tests under Python 3.4.')
115 call(['python3', path_to_runner
])
118 if __name__
== '__main__':
119 sys
.exit(main(sys
.argv
[1:]))