[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.
This commit is contained in:
tobi-wan-kenobi 2020-04-02 16:21:07 +02:00
parent 2756f8fbb3
commit 0f6dfb3f1a
2 changed files with 6 additions and 1 deletions

View file

@ -38,7 +38,7 @@ def __invoke(event, callback):
if not callback: return if not callback: return
if not 'button' in event: return if not 'button' in event: return
for cb in callback.get(event['button']): for cb in callback.get(event['button'], []):
if callable(cb): if callable(cb):
cb(event) cb(event)
else: else:

View file

@ -17,6 +17,11 @@ class config(unittest.TestCase):
core.input.trigger(self.someEvent) core.input.trigger(self.someEvent)
self.callback.assert_called_once_with(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): def test_different_events(self):
core.input.register(self.inputObject, self.someEvent['button'], self.callback) core.input.register(self.inputObject, self.someEvent['button'], self.callback)
core.input.register(self.inputObject, self.anotherEvent['button'], self.callback) core.input.register(self.inputObject, self.anotherEvent['button'], self.callback)