test_task_builtins.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import warnings
  2. from celery.app import app_or_default
  3. from celery.task import ping, PingTask, backend_cleanup
  4. from celery.tests.compat import catch_warnings
  5. from celery.tests.utils import unittest, execute_context
  6. def some_func(i):
  7. return i * i
  8. class test_deprecated(unittest.TestCase):
  9. def test_ping(self):
  10. warnings.resetwarnings()
  11. def block(log):
  12. prev = PingTask.app.conf.CELERY_ALWAYS_EAGER
  13. PingTask.app.conf.CELERY_ALWAYS_EAGER = True
  14. try:
  15. return ping(), log[0].message
  16. finally:
  17. PingTask.app.conf.CELERY_ALWAYS_EAGER = prev
  18. pong, warning = execute_context(catch_warnings(record=True), block)
  19. self.assertEqual(pong, "pong")
  20. self.assertIsInstance(warning, DeprecationWarning)
  21. self.assertIn("ping task has been deprecated",
  22. warning.args[0])
  23. def test_TaskSet_import_from_task_base(self):
  24. warnings.resetwarnings()
  25. def block(log):
  26. from celery.task.base import TaskSet, subtask
  27. x = TaskSet()
  28. y = subtask(PingTask)
  29. return log[0].message, log[1].message
  30. for w in execute_context(catch_warnings(record=True), block):
  31. self.assertIsInstance(w, DeprecationWarning)
  32. self.assertIn("Please use", w.args[0])
  33. class test_backend_cleanup(unittest.TestCase):
  34. def test_run(self):
  35. backend_cleanup.apply()