test_decorators.py 930 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from __future__ import absolute_import, unicode_literals
  2. import warnings
  3. import pytest
  4. from celery.task import base
  5. def add(x, y):
  6. return x + y
  7. @pytest.mark.usefixtures('depends_on_current_app')
  8. class test_decorators:
  9. def test_task_alias(self):
  10. from celery import task
  11. assert task.__file__
  12. assert task(add)
  13. def setup(self):
  14. with warnings.catch_warnings(record=True):
  15. from celery import decorators
  16. self.decorators = decorators
  17. def assert_compat_decorator(self, decorator, type, **opts):
  18. task = decorator(**opts)(add)
  19. assert task(8, 8) == 16
  20. assert isinstance(task, type)
  21. def test_task(self):
  22. self.assert_compat_decorator(self.decorators.task, base.BaseTask)
  23. def test_periodic_task(self):
  24. self.assert_compat_decorator(
  25. self.decorators.periodic_task, base.BaseTask, run_every=1,
  26. )