mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-29 14:37:47 -04:00
68 lines
3.1 KiB
Python
68 lines
3.1 KiB
Python
import argparse
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
repo = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def qml_test_runner():
|
|
override = os.environ.get("QMLTESTRUNNER")
|
|
candidates = [override] if override else ["qmltestrunner6", "/usr/lib/qt6/bin/qmltestrunner", "/usr/lib64/qt6/bin/qmltestrunner", "qmltestrunner"]
|
|
for candidate in candidates:
|
|
executable = shutil.which(candidate)
|
|
if executable:
|
|
return executable
|
|
raise SystemExit("Qt 6 qmltestrunner is required; set QMLTESTRUNNER to its path")
|
|
|
|
|
|
def run(name, command):
|
|
started = time.monotonic()
|
|
try:
|
|
result = subprocess.run(command, cwd=repo, env=dict(os.environ, QT_QPA_PLATFORM="offscreen"), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
|
except OSError as error:
|
|
return name, False, time.monotonic() - started, str(error)
|
|
return name, result.returncode == 0, time.monotonic() - started, result.stdout
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Run shell logic, Qt unit tests and QML widget regressions")
|
|
parser.add_argument("--jobs", type=int, default=max(1, min(4, len(os.sched_getaffinity(0)) // 4)))
|
|
parser.add_argument("suites", nargs="*", choices=["widgets", "media", "qt", "logic"])
|
|
args = parser.parse_args()
|
|
if args.jobs < 1:
|
|
parser.error("--jobs must be positive")
|
|
selected = args.suites or ["widgets", "media", "qt", "logic"]
|
|
fixtures = sorted(str(path.relative_to(repo)) for path in (repo / "quickshell/tests/qml").glob("*.qml"))
|
|
commands = {
|
|
"widgets": [sys.executable, "quickshell/tests/run-surface-fixture.py", *(path for path in fixtures if not path.startswith("quickshell/tests/qml/media-"))],
|
|
"media": [sys.executable, "quickshell/tests/run-surface-fixture.py", "--mpris", "--artwork", *(path for path in fixtures if path.startswith("quickshell/tests/qml/media-"))],
|
|
"logic": ["node", "--test", *sorted(str(path.relative_to(repo)) for path in (repo / "quickshell/tests").glob("*.test.mjs"))],
|
|
}
|
|
if "qt" in selected:
|
|
commands["qt"] = [qml_test_runner(), "-input", "quickshell/tests", "-o", "-,txt"]
|
|
started = time.monotonic()
|
|
failed = False
|
|
with ThreadPoolExecutor(max_workers=min(args.jobs, len(selected))) as pool:
|
|
futures = [pool.submit(run, name, commands[name]) for name in selected]
|
|
for future in as_completed(futures):
|
|
name, passed, elapsed, output = future.result()
|
|
print(f"{'PASS' if passed else 'FAIL'} {name}: {elapsed:.2f}s", flush=True)
|
|
if not passed:
|
|
failed = True
|
|
print(output, flush=True)
|
|
continue
|
|
for line in output.splitlines():
|
|
if name in ["widgets", "media"] or any(token in line for token in ["Totals:", "# tests "]):
|
|
print(line.strip(), flush=True)
|
|
print(f"QML checks: {time.monotonic() - started:.2f}s", flush=True)
|
|
return int(failed)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|