Exemplo n.º 1
0
    def test_once_decorator(self):
        # Register and call twice
        smokesignal.once('foo')(self.fn)
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert self.fn.call_count == 1
Exemplo n.º 2
0
 def test_asynchronous_failure(self):
     """
     Callbacks that raise an exception inside a deferred should trigger
     errbacks.
     """
     smokesignal.once('hello', asynchronous_failure)
     return self._emit(expectFailure=KeyError)
Exemplo n.º 3
0
    def test_once_decorator(self):
        # Register and call twice
        smokesignal.once('foo')(self.fn)
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert self.fn.call_count == 1
Exemplo n.º 4
0
 def test_synchronous_failure(self):
     """
     Callbacks that raise an exception without returning a deferred should
     trigger errbacks.
     """
     smokesignal.once('hello', synchronous_failure)
     return self._emit(expectFailure=ZeroDivisionError)
Exemplo n.º 5
0
    def test_once(self):
        # Register and call twice
        smokesignal.once('foo', self.fn)
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert self.fn.call_count == 1
        assert smokesignal.receivers['foo'] == set()
Exemplo n.º 6
0
    def test_once(self):
        # Register and call twice
        smokesignal.once('foo', self.fn)
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert self.fn.call_count == 1
        assert smokesignal.receivers['foo'] == set()
Exemplo n.º 7
0
 def test_delay(self):
     """
     Similar to test_asynchronous but use deferLater
     """
     smokesignal.once('hello', delay)
     clock = task.Clock()
     pCallLater = patch.object(reactor, 'callLater', clock.callLater)
     with pCallLater:
         r = self._emit(expectSuccess='delay done')
         clock.advance(20)
         return r
Exemplo n.º 8
0
    def test_once_decorator(self):
        # Make a method that has a call count
        def cb():
            cb.call_count += 1
        cb.call_count = 0

        # Register first like a decorator
        smokesignal.once('foo')(cb)
        assert len(smokesignal._receivers['foo']) == 1

        # Call twice
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert cb.call_count == 1
Exemplo n.º 9
0
    def test_once_decorator(self):
        # Make a method that has a call count
        def cb():
            cb.call_count += 1
        cb.call_count = 0

        # Register first like a decorator
        smokesignal.once('foo')(cb)
        assert len(smokesignal._receivers['foo']) == 1

        # Call twice
        smokesignal.emit('foo')
        smokesignal.emit('foo')

        assert cb.call_count == 1
Exemplo n.º 10
0
 def __init__(self):
     smokesignal.once('foo', self.foo)
     self.foo_count = 0
Exemplo n.º 11
0
 def test_once_raises(self):
     with pytest.raises(AssertionError):
         smokesignal.once('foo', 'bar')
Exemplo n.º 12
0
 def __init__(self):
     smokesignal.once('foo', self.foo)
     self.foo_count = 0
Exemplo n.º 13
0
 def test_once_raises(self):
     with pytest.raises(AssertionError):
         smokesignal.once('foo', 'bar')
Exemplo n.º 14
0
 def test_asynchronous(self):
     """
     Callbacks that return deferred should be resolved
     """
     smokesignal.once('hello', asynchronous)
     return self._emit(expectSuccess='asynchronous done')
Exemplo n.º 15
0
 def test_synchronous(self):
     """
     Blocking callbacks should simply fire the deferred
     """
     smokesignal.once('hello', synchronous)
     return self._emit(expectSuccess='synchronous done')