Return a human-readable string description of a task suitable for logging
the status of the task.
"""
+ name = getattr(task, '__name__', None)
if isinstance(task, types.MethodType):
- name = getattr(task, '__name__')
- obj = getattr(task, '__self__')
+ obj = getattr(task, '__self__', None)
if name is not None and obj is not None:
return '%s from %s' % (name, obj)
+ elif isinstance(task, types.FunctionType):
+ if name is not None:
+ return str(name)
return repr(task)
self.mox.VerifyAll()
+class DescriptionTest(mox.MoxTestBase):
+ def test_func(self):
+ def f():
+ pass
+
+ self.assertEqual(scheduler.task_description(f), 'f')
+
+ def test_lambda(self):
+ l = lambda: None
+
+ self.assertEqual(scheduler.task_description(l), '<lambda>')
+
+ def test_method(self):
+ class C(object):
+ def __str__(self):
+ return 'C "o"'
+
+ def __repr__(self):
+ return 'o'
+
+ def m(self):
+ pass
+
+ self.assertEqual(scheduler.task_description(C().m), 'm from C "o"')
+
+ def test_object(self):
+ class C(object):
+ def __str__(self):
+ return 'C "o"'
+
+ def __repr__(self):
+ return 'o'
+
+ def __call__(self):
+ pass
+
+ self.assertEqual(scheduler.task_description(C()), 'o')
+
+
class WrapperTaskTest(mox.MoxTestBase):
def test_wrap(self):