Files
NexaLogi/tests/test_autostart.py
T
nessi 454cad95c5 Add project infrastructure and core application files
Add .gitignore, GitLab CI pipeline with test/lint/build/release stages, project documentation (README, LICENSE, CHANGELOG, CONTRIBUTING, SECURITY), PyInstaller packaging configuration with icon and version info, Python project configuration with dependencies, and complete application source including battery provider, device discovery, settings management, UI components, startup control, and comprehensive test suite
2026-06-21 11:07:05 +02:00

47 lines
1.3 KiB
Python

from contextlib import nullcontext
from unittest.mock import MagicMock
from logitech_battery_widget.windows import autostart
def registry_mock():
registry = MagicMock()
registry.HKEY_CURRENT_USER = object()
registry.KEY_READ = 1
registry.KEY_SET_VALUE = 2
registry.REG_SZ = 1
key = MagicMock()
registry.OpenKey.return_value = nullcontext(key)
registry.CreateKeyEx.return_value = nullcontext(key)
return registry, key
def test_enable_writes_current_user_run_value():
registry, key = registry_mock()
autostart.set_enabled(True, registry)
registry.SetValueEx.assert_called_once_with(
key, autostart.VALUE_NAME, 0, registry.REG_SZ, autostart.launch_command()
)
def test_disable_removes_value_without_real_registry():
registry, key = registry_mock()
autostart.set_enabled(False, registry)
registry.DeleteValue.assert_called_once_with(key, autostart.VALUE_NAME)
def test_is_enabled_compares_exact_command():
registry, _ = registry_mock()
registry.QueryValueEx.return_value = (autostart.launch_command(), registry.REG_SZ)
assert autostart.is_enabled(registry)
def test_missing_value_is_disabled():
registry, _ = registry_mock()
registry.QueryValueEx.side_effect = FileNotFoundError
assert not autostart.is_enabled(registry)