test_result.py 891 B

123456789101112131415161718192021222324252627282930
  1. from __future__ import absolute_import, unicode_literals
  2. from case import patch
  3. from celery.five import WhateverIO
  4. from celery.bin.result import result
  5. class test_result:
  6. def setup(self):
  7. @self.app.task(shared=False)
  8. def add(x, y):
  9. return x + y
  10. self.add = add
  11. def test_run(self):
  12. with patch('celery.result.AsyncResult.get') as get:
  13. out = WhateverIO()
  14. r = result(app=self.app, stdout=out)
  15. get.return_value = 'Jerry'
  16. r.run('id')
  17. assert 'Jerry' in out.getvalue()
  18. get.return_value = 'Elaine'
  19. r.run('id', task=self.add.name)
  20. assert 'Elaine' in out.getvalue()
  21. with patch('celery.result.AsyncResult.traceback') as tb:
  22. r.run('id', task=self.add.name, traceback=True)
  23. assert str(tb) in out.getvalue()