def test_Event_SubscribeAndFireWithDupplicateKeyword_RaisesException(self): mockListener = mock.Mock() event = Event() event.subscribe(mockListener, kword1="value1") with self.assertRaises(DuplicateKeywordArgument): event.fire(kword1="value2")
def test_Event_SubscribeWithArgsAndKwargsFireWithArgsAndKwargs_ListenerIsCalledWithMergedArguments(self): mockListener = mock.Mock() event = Event() event.subscribe(mockListener, "arg1", "arg2", kword1="value1", kword2="value2") event.fire("arg3", "arg4", kword3="value3", kword4="value4") mockListener.assert_called_with('arg1', 'arg2', 'arg3', 'arg4', kword4='value4', kword3='value3', kword2='value2', kword1='value1')
def test_Event_FireUsingDifferentCallMethod_CallMethodIsCalled(self): mock_call_method = mock.Mock() event = Event(call_method=mock_call_method) event.subscribe("fct1", "arg1") event.fire("arg2") mock_call_method.assert_called_with("fct1", "arg1", "arg2")
def test_Event_UnsubscribeItselfInACallBack_CallbackIsUnsubscribed(self): def unsubscriber_callback(event): event.unsubscribe(unsubscriber_callback) event = Event() event.subscribe(unsubscriber_callback, event=event) event.fire() self.assertFalse(event.is_subscribed(unsubscriber_callback))
def test_Event_SubscribeInACallBack_CallbackIsSubscribed(self): def subscriber_callback(event, callback2): event.subscribe(callback2) event = Event() event.subscribe(subscriber_callback, event=event, callback2="callback1") event.fire() self.assertTrue(event.is_subscribed("callback1"))