Store correct function for once events

The handler was always stored even when the event was a once event and
thus was wrapped in once_wrapper.

This handles the once correctly.
pull/2338/head
Åke Forslund 2019-09-30 10:51:32 +02:00
parent 87ee92d4f5
commit 425feb0590
2 changed files with 6 additions and 2 deletions

View File

@ -138,9 +138,12 @@ class EventContainer:
if handler:
if once:
self.bus.once(name, once_wrapper)
self.events.append((name, once_wrapper))
else:
self.bus.on(name, handler)
self.events.append((name, handler))
self.events.append((name, handler))
LOG.debug('Added event: {}'.format(name))
def remove(self, name):
"""Removes an event from bus emitter and events list.

View File

@ -32,12 +32,13 @@ class TestEventContainer(unittest.TestCase):
self.assertTrue(bus.on.called)
# Test add single shot event handler
len_before = len(container.events)
container.add('test2', example_handler, once=True)
self.assertEqual(len_before + 1, len(container.events))
self.assertTrue(bus.once.called)
# Verify correct content in event container
self.assertTrue(('test1', example_handler) in container.events)
self.assertTrue(('test2', example_handler) in container.events)
self.assertEqual(len(container.events), 2)
def test_remove(self):