def test_registerHandler_during_fire(self): event = Event() event.registerHandler(event.registerHandler) event.fire(sentinel.otherHandler) self.assertItemsEqual( [event.registerHandler, sentinel.otherHandler], event.handlers )
def test_fire_calls_all_handlers(self): event = Event() handler_one = MagicMock() handler_two = MagicMock() event.registerHandler(handler_one) event.registerHandler(handler_two) args = [factory.make_name("arg") for _ in range(3)] kwargs = { factory.make_name("key"): factory.make_name("value") for _ in range(3) } event.fire(*args, **kwargs) self.assertThat(handler_one, MockCalledOnceWith(*args, **kwargs)) self.assertThat(handler_two, MockCalledOnceWith(*args, **kwargs))
def test_unregisterHandler_during_fire(self): event = Event() event.registerHandler(event.unregisterHandler) event.fire(event.unregisterHandler) self.assertItemsEqual([], event.handlers)
def test_unregisterHandler(self): event = Event() event.registerHandler(sentinel.handler) event.unregisterHandler(sentinel.handler) self.assertItemsEqual([], event.handlers)