def test_subscribed_functions_called_in_sequence(self, signal: SimpleSignal): order = [] for c in range(100): signal.subscribe(partial(order.append, c)) signal() assert len(order) == 100 assert order == sorted(order)
def test_subscribed_functions_invoked_on_call(self, signal: SimpleSignal): f = mock.Mock() signal.subscribe(f) signal(1, 2, 3, val=2) f.assert_called_with(1, 2, 3, val=2)
def test_broken_subscriber(self, signal: SimpleSignal): subs = [mock.Mock(), mock.Mock(), mock.Mock()] subs[1].side_effect = TExc() for s in subs: signal.subscribe(s) with pytest.raises(TExc): signal(1, 2) subs[0].assert_called_once_with(1, 2) subs[1].assert_called_once_with(1, 2) subs[2].assert_not_called()
def test_calling_cleaned_signal_raises_exception(self, signal: SimpleSignal): signal.clean() with pytest.raises(Exception): signal()
def test_allows_function_registration(self, signal: SimpleSignal): def foo(*args, **kwargs): pass signal.subscribe(foo)
def signal(self): return SimpleSignal()