Esempio n. 1
0
 def test_registerHandler_during_fire(self):
     event = Event()
     event.registerHandler(event.registerHandler)
     event.fire(sentinel.otherHandler)
     self.assertItemsEqual(
         [event.registerHandler, sentinel.otherHandler], event.handlers
     )
Esempio n. 2
0
 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))
Esempio n. 3
0
 def test_unregisterHandler_during_fire(self):
     event = Event()
     event.registerHandler(event.unregisterHandler)
     event.fire(event.unregisterHandler)
     self.assertItemsEqual([], event.handlers)
Esempio n. 4
0
 def test_unregisterHandler(self):
     event = Event()
     event.registerHandler(sentinel.handler)
     event.unregisterHandler(sentinel.handler)
     self.assertItemsEqual([], event.handlers)