Files
dotfiles/quickshell/tests/power_controller.py
T
2026-11-17 18:15:16 +07:00

29 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Run Quickshell's real Process-backed controller exclusively against a fake helper."""
import os
from pathlib import Path
import subprocess
import tempfile
import shutil
fixture = Path(__file__).resolve().parent / 'fixtures/power.qml'
with tempfile.TemporaryDirectory(prefix='adaptive-power-controller-') as tmp:
runtime = Path(tmp, 'runtime')
runtime.mkdir(mode=0o700)
env = dict(os.environ, QT_QPA_PLATFORM='offscreen', XDG_RUNTIME_DIR=str(runtime),
XDG_STATE_HOME=tmp, XDG_CACHE_HOME=tmp)
# Quickshell resolves directory imports inside its config root: stage the exact controller
# source beside the fixture so the offscreen shell has no access to production entrypoints.
config = Path(tmp, 'config')
config.mkdir()
shutil.copyfile(fixture, config / 'shell.qml')
shutil.copyfile(fixture.parents[2] / 'services/PowerController.qml', config / 'PowerController.qml')
shutil.copyfile(fixture.parents[1] / 'power_fake.py', config / 'power_fake.py')
result = subprocess.run(['quickshell', '-p', str(config), '--no-color'], env=env,
capture_output=True, text=True, timeout=25)
logs = result.stdout + result.stderr
print(logs)
assert result.returncode == 0 and 'POWER_TEST_PASS: 7 scenarios' in logs, logs
for marker in ['POWER_TEST_FAIL', 'Failed to load configuration', 'ReferenceError', 'TypeError', 'Binding loop']:
assert marker not in logs, marker