예제 #1
0
    def test_name_is_the_name_of_the_wrapped_callable(self):
        def foo():
            pass

        foo.__name__ = "random_name_%d" % random.randint(1000, 2000)
        task = tasks.WrappedCallableTask(foo)
        self.assertEqual(task.name, foo.__name__)
예제 #2
0
    def test_reads_double_under_doc_from_callable(self):
        def foo():
            pass

        foo.__doc__ = "Some random __doc__: %d" % random.randint(1000, 2000)
        task = tasks.WrappedCallableTask(foo)
        self.assertEqual(task.__doc__, foo.__doc__)
예제 #3
0
    def test_allows_any_number_of_kwargs(self):
        kwargs = dict([("key%d" % i, i) for i in range(random.randint(0, 10))])

        def foo():
            pass

        task = tasks.WrappedCallableTask(foo, **kwargs)
예제 #4
0
    def test_allows_any_number_of_args(self):
        args = [i for i in range(random.randint(0, 10))]

        def foo():
            pass

        task = tasks.WrappedCallableTask(foo, *args)
예제 #5
0
 def test_passes_all_regular_args_to_run(self):
     def foo(*args): return args
     random_args = tuple(
         [random.randint(1000, 2000) for i in range(random.randint(1, 5))]
     )
     task = tasks.WrappedCallableTask(foo)
     self.assertEqual(random_args, task(*random_args))
예제 #6
0
    def test_dispatches_to_wrapped_callable_on_run(self):
        random_value = "some random value %d" % random.randint(1000, 2000)

        def foo():
            return random_value

        task = tasks.WrappedCallableTask(foo)
        self.assertEqual(random_value, task())
예제 #7
0
    def test_calling_the_object_is_the_same_as_run(self):
        random_return = random.randint(1000, 2000)

        def foo():
            return random_return

        task = tasks.WrappedCallableTask(foo)
        self.assertEqual(task(), task.run())
예제 #8
0
 def test_passes_all_keyword_args_to_run(self):
     def foo(**kwargs): return kwargs
     random_kwargs = {}
     for i in range(random.randint(1, 5)):
         random_key = ("foo", "bar", "baz", "foobar", "barfoo")[i]
         random_kwargs[random_key] = random.randint(1000, 2000)
     task = tasks.WrappedCallableTask(foo)
     self.assertEqual(random_kwargs, task(**random_kwargs))
예제 #9
0
def _wrap_as_new(original, new):
    if isinstance(original, tasks.Task):
        return tasks.WrappedCallableTask(new)
    return new
예제 #10
0
    def test_run_is_wrapped_callable(self):
        def foo():
            pass

        task = tasks.WrappedCallableTask(foo)
        self.assertEqual(task.wrapped, foo)
예제 #11
0
def task(func):
    """
    Decorator declaring the wrapped function as a :ref:`new-style task <new-style-tasks>`.
    """
    return tasks.WrappedCallableTask(func)