2018-12-05 18:53:33 -05:00
|
|
|
#!/usr/bin/env xonsh
|
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
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
import xonsh.cli_utils as xcli
|
|
|
|
|
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
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
def test(
|
|
|
|
report_cov: xcli.Arg('--report-coverage', '-c', action="store_true") = False,
|
|
|
|
no_amalgam: xcli.Arg('--no-amalgam', '-n', action="store_true") = False,
|
|
|
|
pytest_args: xcli.Arg(nargs='*')=(),
|
|
|
|
):
|
2020-10-19 21:22:37 +05:30
|
|
|
"""Run pytest.
|
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
report_cov
|
|
|
|
Report coverage at the end of the test
|
|
|
|
pytest_args
|
|
|
|
arbitrary arguments that gets passed to pytest's invocation.
|
|
|
|
Use %%d to parameterize and prevent overwrite
|
|
|
|
no_amalgam
|
|
|
|
Disable amalgamation check
|
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
Examples
|
|
|
|
--------
|
|
|
|
`xonsh run-tests.xsh -- --junitxml=junit/test-results.%%d.xml`
|
|
|
|
"""
|
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
if (not no_amalgam) and not $(xonsh -c "import xonsh.main; print(xonsh.main.__file__, end='')").endswith("__amalgam__.py"):
|
2021-05-28 15:42:37 +03:00
|
|
|
echo "Tests need to run from the amalgamated xonsh! install with `pip install .` (without `-e`)"
|
|
|
|
exit(1)
|
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
if report_cov:
|
2021-06-07 23:10:40 +05:30
|
|
|
$XONSH_NO_AMALGAMATE = True
|
2021-08-28 16:10:26 +05:30
|
|
|
![pytest @(_replace_args(pytest_args, 0)) --cov --cov-report=xml --cov-report=term]
|
2020-12-18 19:34:42 +05:30
|
|
|
else:
|
2021-08-28 16:10:26 +05:30
|
|
|
# during CI run, some tests take longer to complete on windows
|
|
|
|
![pytest @(_replace_args(pytest_args, 0)) --durations=5]
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
|
2021-08-28 16:10:26 +05:30
|
|
|
def qa():
|
2020-10-19 21:22:37 +05:30
|
|
|
"""QA checks"""
|
2021-06-07 23:10:40 +05:30
|
|
|
$XONSH_NO_AMALGAMATE = True
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
2021-06-11 17:31:35 +05:30
|
|
|
echo "---------- Running news items check ----------"
|
|
|
|
pytest -m news
|
|
|
|
|
2020-10-19 21:22:37 +05:30
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-08-28 16:10:26 +05:30
|
|
|
parser = xcli.make_parser("test commands")
|
|
|
|
parser.add_command(test)
|
|
|
|
parser.add_command(qa)
|
|
|
|
|
2020-11-10 11:07:40 +05:30
|
|
|
try:
|
2021-08-28 16:10:26 +05:30
|
|
|
xcli.dispatch(parser)
|
2020-11-10 11:07:40 +05:30
|
|
|
except subprocess.CalledProcessError as ex:
|
|
|
|
parser.exit(1, f"Failed with {ex}")
|