예제 #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
예제 #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)
예제 #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
예제 #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)
예제 #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()
예제 #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()
예제 #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
예제 #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
예제 #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
예제 #10
0
 def __init__(self):
     smokesignal.once('foo', self.foo)
     self.foo_count = 0
예제 #11
0
 def test_once_raises(self):
     with pytest.raises(AssertionError):
         smokesignal.once('foo', 'bar')
예제 #12
0
 def __init__(self):
     smokesignal.once('foo', self.foo)
     self.foo_count = 0
예제 #13
0
 def test_once_raises(self):
     with pytest.raises(AssertionError):
         smokesignal.once('foo', 'bar')
예제 #14
0
 def test_asynchronous(self):
     """
     Callbacks that return deferred should be resolved
     """
     smokesignal.once('hello', asynchronous)
     return self._emit(expectSuccess='asynchronous done')
예제 #15
0
 def test_synchronous(self):
     """
     Blocking callbacks should simply fire the deferred
     """
     smokesignal.once('hello', synchronous)
     return self._emit(expectSuccess='synchronous done')