コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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()
コード例 #4
0
 def test_calling_cleaned_signal_raises_exception(self, signal: SimpleSignal):
     signal.clean()
     with pytest.raises(Exception):
         signal()
コード例 #5
0
    def test_allows_function_registration(self, signal: SimpleSignal):
        def foo(*args, **kwargs):
            pass

        signal.subscribe(foo)
コード例 #6
0
 def signal(self):
     return SimpleSignal()