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

32 lines
1.2 KiB
Python

import importlib.util
from pathlib import Path
from types import SimpleNamespace
path = Path(__file__).resolve().parents[1] / 'backend' / 'power_profiles.py'
spec = importlib.util.spec_from_file_location('power_profiles', path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
def test_get():
def runner(args, **kwargs):
assert args == ['powerprofilesctl', 'get']
return SimpleNamespace(returncode=0, stdout='balanced\n', stderr='')
assert module.execute(['get'], runner=runner, which=lambda _: '/bin/powerprofilesctl')['profile'] == 'balanced'
def test_invalid_profile_never_invokes_command():
def runner(*args, **kwargs):
raise AssertionError('must not run')
assert not module.execute(['set', ';reboot'], runner=runner, which=lambda _: '/bin/powerprofilesctl')['ok']
def test_missing_utility():
assert not module.execute(['get'], which=lambda _: None)['ok']
def test_backend_failure():
def runner(args, **kwargs):
return SimpleNamespace(returncode=1, stdout='', stderr='denied')
assert 'denied' in module.execute(['set', 'balanced'], runner=runner, which=lambda _: '/bin/powerprofilesctl')['error']