|
3 | 3 | # We want to ensure we're importing from the installed
|
4 | 4 | # binary package not from the CWD.
|
5 | 5 |
|
| 6 | +import argparse |
6 | 7 | import os
|
7 |
| -import sys |
8 | 8 | from subprocess import check_call
|
9 | 9 |
|
10 | 10 | _dname = os.path.dirname
|
11 | 11 |
|
12 | 12 | REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
|
13 |
| -os.chdir(os.path.join(REPO_ROOT, 'tests')) |
| 13 | +PACKAGE = "boto3" |
| 14 | +os.chdir(os.path.join(REPO_ROOT, "tests")) |
14 | 15 |
|
15 |
| -args = sys.argv[1:] |
16 |
| -if not args: |
17 |
| - args = ['unit/', 'functional/'] |
18 | 16 |
|
19 |
| -check_call(['nosetests', '--with-coverage', '--cover-erase', |
20 |
| - '--cover-package', 'boto3', '--with-xunit', '--cover-xml', |
21 |
| - '-v'] + args) |
| 17 | +def run(command): |
| 18 | + return check_call(command, shell=True) |
| 19 | + |
| 20 | + |
| 21 | +def process_args(args): |
| 22 | + runner = args.test_runner |
| 23 | + test_args = '' |
| 24 | + if args.with_cov: |
| 25 | + test_args += ( |
| 26 | + f"--with-xunit --cover-erase --with-coverage " |
| 27 | + f"--cover-package {PACKAGE} --cover-xml -v " |
| 28 | + ) |
| 29 | + dirs = " ".join(args.test_dirs) |
| 30 | + |
| 31 | + return runner, test_args, dirs |
| 32 | + |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + parser = argparse.ArgumentParser() |
| 36 | + parser.add_argument( |
| 37 | + "test_dirs", |
| 38 | + default=["unit/", "functional/"], |
| 39 | + nargs="*", |
| 40 | + help="One or more directories containing tests.", |
| 41 | + ) |
| 42 | + parser.add_argument( |
| 43 | + "-r", |
| 44 | + "--test-runner", |
| 45 | + default="nosetests", |
| 46 | + help="Test runner to execute tests. Defaults to nose.", |
| 47 | + ) |
| 48 | + parser.add_argument( |
| 49 | + "-c", |
| 50 | + "--with-cov", |
| 51 | + default=False, |
| 52 | + action="store_true", |
| 53 | + help="Run default test-runner with code coverage enabled.", |
| 54 | + ) |
| 55 | + raw_args = parser.parse_args() |
| 56 | + test_runner, test_args, test_dirs = process_args(raw_args) |
| 57 | + |
| 58 | + cmd = f"{test_runner} {test_args}{test_dirs}" |
| 59 | + print(f"Running {cmd}...") |
| 60 | + run(cmd) |
0 commit comments