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