def test_only_once(self): """ Subscribes to an event only once""" emitter = Emitter() def callmeonce(): self.assertNotIn('test', emitter._e) emitter.once('test', callmeonce) emitter.emit('test')
def test_only_once_context(self): """ Subscribing to an event only once keeps context """ emitter = Emitter() context = {'context_value': True} def callmeonce(context_value=None): self.assertTrue(context_value) self.assertNotIn('test', emitter._e) emitter.once('test', callmeonce, context) emitter.emit('test')