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']