54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Run Nexus Baota/BtPanel backend tests with environment guard."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DEFAULT_TESTS = [
|
|
"tests/test_btpanel_bootstrap_lock.py",
|
|
"tests/test_btpanel_bootstrap_loop.py",
|
|
"tests/test_btpanel_client.py",
|
|
"tests/test_btpanel_file_urls.py",
|
|
"tests/test_btpanel_get_config.py",
|
|
"tests/test_btpanel_login_url.py",
|
|
"tests/test_btpanel_login_url_route.py",
|
|
"tests/test_btpanel_server_list.py",
|
|
"tests/test_btpanel_ssh_bootstrap.py",
|
|
"tests/test_btpanel_ssh_login.py",
|
|
"tests/test_btpanel_temp_login_ttl.py",
|
|
]
|
|
|
|
|
|
def run(cmd: list[str], *, check: bool = True) -> int:
|
|
print("\n$ " + " ".join(cmd), flush=True)
|
|
proc = subprocess.run(cmd, cwd=ROOT)
|
|
if check and proc.returncode != 0:
|
|
raise SystemExit(proc.returncode)
|
|
return proc.returncode
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--skip-env-check", action="store_true", help="Skip Python version/dependency guard.")
|
|
parser.add_argument("pytest_args", nargs=argparse.REMAINDER, help="Extra pytest arguments appended after default tests. Use -- before options, e.g. -- -q.")
|
|
args = parser.parse_args()
|
|
|
|
if not args.skip_env_check:
|
|
run([sys.executable, "scripts/check_backend_test_env.py"])
|
|
|
|
pytest_args = list(args.pytest_args)
|
|
if pytest_args and pytest_args[0] == "--":
|
|
pytest_args = pytest_args[1:]
|
|
|
|
cmd = [sys.executable, "-m", "pytest", *DEFAULT_TESTS, *pytest_args]
|
|
return run(cmd, check=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|