def test_name_given(self): deferred.defer(top_level_function, _name='taskname') assert not self.taskqueue.called self.defer.assert_called_once_with( top_level_function, _name='taskname', _queue='somequeue', _target='somemodule', )
def test_non_default_target(self): deferred.defer(top_level_function, _target='differentmodule') assert not self.taskqueue.called self.defer.assert_called_once_with( top_level_function, _name=mock.ANY, _queue='somequeue', _target='differentmodule', )
def test_taskqueue_params(self): decorated = deferred.deferred('some/path')(top_level_function) deferred.defer(decorated, _target='othermodule', _queue='otherqueue') assert not self.defer.called assert self.taskqueue.called kwargs = self.taskqueue.call_args[1] assert kwargs['url'] == '/defer/some/path' assert kwargs['method'] == 'POST' assert kwargs['payload'] assert kwargs['queue_name'] == 'otherqueue' assert kwargs['_target'] == 'othermodule'
def maybeDeferredGenerator(f, *args, **kw): try: result = f(*args, **kw) except Exception, e: tb = traceback.format_exc() if not hasattr(e, "_monocle"): e._monocle = {'tracebacks': []} e._monocle['tracebacks'].append(tb) return defer(e)
def test_name_random(self): deferred.defer(top_level_function) assert not self.taskqueue.called name = self.defer.call_args[1]['_name'] assert name.startswith('top_level_function-') assert len(name) == (len('top_level_function-') + 32)
state['waiting'] = False return deferred to_gen = state['result'] def maybeDeferredGenerator(f, *args, **kw): try: result = f(*args, **kw) except Exception, e: print e tb = traceback.format_exc() if not hasattr(e, "_tb"): e._tb = {'tracebacks': []} e._tb['tracebacks'].append(tb) return defer(e) if isinstance(result, types.GeneratorType): return _chain(None, result, Deferred()) elif isinstance(result, Deferred): return result return defer(result) def inline(f): def unwindGenerator(*args, **kwargs): return maybeDeferredGenerator(f, *args, **kwargs) return mergeFunctionMetadata(f, unwindGenerator)