feat(app-binding): lier les presets aux applications

Ajoute la configuration des associations application/preset, le service de suivi du focus, l'intégration GUI et les fichiers d'installation nécessaires.

Ajoute les tests unitaires ciblés des bindings, du service de focus, des migrations et des composants GUI associés.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 23:52:34 +02:00
parent 0ab77d2a64
commit 9ef2c1439c
42 changed files with 4353 additions and 12 deletions

View File

@ -1625,3 +1625,73 @@ class TestController(unittest.TestCase):
output_type=None,
output_code=None,
)
@test_setup
class TestControllerAppBindings(unittest.TestCase):
def setUp(self) -> None:
self.message_broker = MessageBroker()
self.data_manager = MagicMock()
self.controller = Controller(self.message_broker, self.data_manager)
self.user_interface = MagicMock()
self.controller.set_gui(self.user_interface)
def test_load_app_bindings(self):
self.controller.load_app_bindings()
self.data_manager.publish_app_bindings.assert_called_once()
def test_set_app_binding_enabled_true_starts_service(self):
with patch(
"inputremapper.gui.controller.ensure_focus_service_running"
) as ensure, patch(
"inputremapper.gui.controller.GLib.timeout_add"
) as timeout_add:
self.controller.set_app_binding_enabled(True)
ensure.assert_called_once()
self.data_manager.set_app_binding_enabled.assert_called_once_with(True)
# a delayed status refresh is scheduled
timeout_add.assert_called_once()
def test_set_app_binding_enabled_false_does_not_start_service(self):
with patch(
"inputremapper.gui.controller.ensure_focus_service_running"
) as ensure, patch(
"inputremapper.gui.controller.GLib.timeout_add"
) as timeout_add:
self.controller.set_app_binding_enabled(False)
ensure.assert_not_called()
self.data_manager.set_app_binding_enabled.assert_called_once_with(False)
timeout_add.assert_not_called()
def test_refresh_app_bindings_once(self):
result = self.controller._refresh_app_bindings_once()
self.assertFalse(result) # GLib: do not repeat
self.data_manager.publish_app_bindings.assert_called_once()
def test_update_app_bindings(self):
from inputremapper.configs.app_binding import AppBinding
bindings = [AppBinding(app_id="firefox")]
self.controller.update_app_bindings(bindings)
self.data_manager.set_app_bindings.assert_called_once_with(bindings)
def test_update_app_bindings_permission_error(self):
self.data_manager.set_app_bindings.side_effect = PermissionError("nope")
with patch.object(self.controller, "show_status") as show_status:
self.controller.update_app_bindings([])
show_status.assert_called_once()
self.assertEqual(show_status.call_args[0][0], CTX_ERROR)
def test_get_presets_for_group(self):
self.data_manager.get_presets_for_group.return_value = ("a", "b")
result = self.controller.get_presets_for_group("Foo Device")
self.assertEqual(result, ("a", "b"))
self.data_manager.get_presets_for_group.assert_called_once_with("Foo Device")
def test_start_and_stop_app_detection(self):
self.controller.start_app_detection()
self.data_manager.start_app_detection.assert_called_once()
self.controller.stop_app_detection()
self.data_manager.stop_app_detection.assert_called_once()