2018-12-05 18:53:33 -05:00
|
|
|
#!/usr/bin/env xonsh
|
2020-10-19 21:22:37 +05:30
|
|
|
import argparse
|
2020-11-10 11:07:40 +05:30
|
|
|
import subprocess
|
2020-10-19 21:22:37 +05:30
|
|
|
from typing import List
|
2019-04-29 17:07:09 +09:00
|
|
|
|
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
$RAISE_SUBPROC_ERROR = True
|
2021-05-28 15:42:37 +03:00
|
|
|
# $XONSH_NO_AMALGAMATE = 1
|
2020-12-18 19:34:42 +05:30
|
|
|
# $XONSH_TRACE_SUBPROC = True
|
2019-04-29 17:07:09 +09:00
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
|
2020-11-10 11:07:40 +05:30
|
|
|
def _replace_args(args: List[str], num: int) -> List[str]:
|
2019-04-29 17:07:09 +09:00
|
|
|
return [
|
2020-10-19 21:22:37 +05:30
|
|
|
(arg % num) if "%d" in arg else arg
|
|
|
|
for arg in args
|
|
|
|
]
|
2019-04-29 17:07:09 +09:00
|
|
|
|
2018-12-05 18:53:33 -05:00
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
def test(ns: argparse.Namespace):
|
|
|
|
"""Run pytest.
|
|
|
|
|
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
`xonsh run-tests.xsh -- --junitxml=junit/test-results.%%d.xml`
|
|
|
|
"""
|
|
|
|
|
2020-12-18 19:34:42 +05:30
|
|
|
args = ns.pytest_args
|
2020-10-19 21:22:37 +05:30
|
|
|
|
2021-05-28 15:42:37 +03:00
|
|
|
if not $(xonsh -c "import xonsh.main; print(xonsh.main.__file__, end='')").endswith("__amalgam__.py"):
|
|
|
|
echo "Tests need to run from the amalgamated xonsh! install with `pip install .` (without `-e`)"
|
|
|
|
exit(1)
|
|
|
|
|
2020-12-18 19:34:42 +05:30
|
|
|
if ns.report_coverage:
|
2021-05-20 15:44:26 +05:30
|
|
|
![pytest @(_replace_args(args, 0)) --cov --cov-report=xml --cov-report=term]
|
2020-12-18 19:34:42 +05:30
|
|
|
else:
|
2021-05-20 15:44:26 +05:30
|
|
|
![pytest @(_replace_args(args, 0))]
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
|
|
|
|
def qa(ns: argparse.Namespace):
|
|
|
|
"""QA checks"""
|
|
|
|
|
|
|
|
echo "---------- Check Black formatter -----------"
|
2021-05-20 15:44:26 +05:30
|
|
|
black --check xonsh xontrib tests
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
echo "---------- Running flake8 ----------"
|
|
|
|
python -m flake8
|
|
|
|
|
|
|
|
echo "---------- Running mypy ----------"
|
|
|
|
mypy --version
|
2021-05-20 15:44:26 +05:30
|
|
|
# todo: add xontrib folder here
|
2021-05-06 19:24:09 +05:30
|
|
|
mypy xonsh --exclude xonsh/ply
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
2020-10-29 18:19:08 +01:00
|
|
|
parser.set_defaults(func=lambda *args: parser.print_help())
|
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
commands = parser.add_subparsers()
|
|
|
|
|
|
|
|
test_parser = commands.add_parser('test', help=test.__doc__)
|
|
|
|
test_parser.add_argument(
|
|
|
|
'pytest_args',
|
|
|
|
nargs='*',
|
|
|
|
help="arbitrary arguments that gets passed to pytest's invocation."
|
|
|
|
" Use %%d to parameterize and prevent overwrite "
|
|
|
|
)
|
2020-12-18 19:34:42 +05:30
|
|
|
test_parser.add_argument(
|
|
|
|
'--report-coverage',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Report coverage at the end of the test",
|
|
|
|
)
|
2020-10-19 21:22:37 +05:30
|
|
|
test_parser.set_defaults(func=test)
|
|
|
|
|
|
|
|
qa_parser = commands.add_parser('qa', help=qa.__doc__)
|
|
|
|
qa_parser.set_defaults(func=qa)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2020-11-10 11:07:40 +05:30
|
|
|
try:
|
|
|
|
args.func(args)
|
|
|
|
except subprocess.CalledProcessError as ex:
|
|
|
|
parser.exit(1, f"Failed with {ex}")
|