39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
"""Run staged backend tests from public Python copies in a clean local runtime."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import faulthandler
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
SOURCE = Path("C:/kefu/wechat_rpa")
|
|
RUNTIME = HERE / "runtime"
|
|
RUNTIME.mkdir(exist_ok=True)
|
|
for source in SOURCE.glob("*.py"):
|
|
shutil.copyfile(source, RUNTIME / source.name)
|
|
for source in (HERE / "payload").glob("*.py"):
|
|
shutil.copyfile(source, RUNTIME / source.name)
|
|
os.chdir(RUNTIME)
|
|
allowed = {key: value for key, value in os.environ.items()
|
|
if key.upper() in {"SYSTEMROOT", "WINDIR", "TEMP", "TMP"}}
|
|
os.environ.clear()
|
|
os.environ.update(allowed)
|
|
TEMP_ROOT = RUNTIME / "temp"
|
|
TEMP_ROOT.mkdir(exist_ok=True)
|
|
os.environ.update({"TEMP": str(TEMP_ROOT), "TMP": str(TEMP_ROOT)})
|
|
tempfile.tempdir = str(TEMP_ROOT)
|
|
sys.path.insert(0, str(RUNTIME))
|
|
faulthandler.enable()
|
|
faulthandler.dump_traceback_later(45, repeat=True)
|
|
names = sys.argv[1:] or ["test_basic_role_edit", "test_group_sso", "test_group_authorization", "test_admin_api"]
|
|
# The existing authorization module creates its own public-code mirror and
|
|
# changes sys.path during import. Load the other staged test modules first.
|
|
names.sort(key=lambda name: name.split(".")[0] == "test_group_authorization")
|
|
suite = unittest.defaultTestLoader.loadTestsFromNames(names)
|
|
result = unittest.TextTestRunner(verbosity=2).run(suite)
|
|
raise SystemExit(0 if result.wasSuccessful() else 1)
|