From 0f6dfb3f1ae4f504671853b3fd2fec7e1c52a5c6 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 2 Apr 2020 16:21:07 +0200 Subject: [PATCH] [core/input] do not throw on wrong event type until now, if a module had registered callbacks, events for nonexistent buttons caused the trigger mechanism to raise an exception. --- core/input.py | 2 +- tests/core/test_input.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/input.py b/core/input.py index cc450c7..fce461e 100644 --- a/core/input.py +++ b/core/input.py @@ -38,7 +38,7 @@ def __invoke(event, callback): if not callback: return if not 'button' in event: return - for cb in callback.get(event['button']): + for cb in callback.get(event['button'], []): if callable(cb): cb(event) else: diff --git a/tests/core/test_input.py b/tests/core/test_input.py index e469543..8e68f4c 100644 --- a/tests/core/test_input.py +++ b/tests/core/test_input.py @@ -17,6 +17,11 @@ class config(unittest.TestCase): core.input.trigger(self.someEvent) self.callback.assert_called_once_with(self.someEvent) + def test_nonexistent_callback(self): + core.input.register(self.inputObject, self.someEvent['button'], self.callback) + core.input.trigger(self.anotherEvent) + self.callback.assert_not_called() + def test_different_events(self): core.input.register(self.inputObject, self.someEvent['button'], self.callback) core.input.register(self.inputObject, self.anotherEvent['button'], self.callback)