test_defaults.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import absolute_import, unicode_literals
  2. import sys
  3. from importlib import import_module
  4. from case import mock
  5. from celery.app.defaults import (
  6. _OLD_DEFAULTS, _OLD_SETTING_KEYS, _TO_NEW_KEY, _TO_OLD_KEY,
  7. DEFAULTS, NAMESPACES, SETTING_KEYS
  8. )
  9. from celery.five import values
  10. class test_defaults:
  11. def setup(self):
  12. self._prev = sys.modules.pop('celery.app.defaults', None)
  13. def teardown(self):
  14. if self._prev:
  15. sys.modules['celery.app.defaults'] = self._prev
  16. def test_option_repr(self):
  17. assert repr(NAMESPACES['broker']['url'])
  18. def test_any(self):
  19. val = object()
  20. assert self.defaults.Option.typemap['any'](val) is val
  21. @mock.sys_platform('darwin')
  22. @mock.pypy_version((1, 4, 0))
  23. def test_default_pool_pypy_14(self):
  24. assert self.defaults.DEFAULT_POOL == 'solo'
  25. @mock.sys_platform('darwin')
  26. @mock.pypy_version((1, 5, 0))
  27. def test_default_pool_pypy_15(self):
  28. assert self.defaults.DEFAULT_POOL == 'prefork'
  29. def test_compat_indices(self):
  30. assert not any(key.isupper() for key in DEFAULTS)
  31. assert not any(key.islower() for key in _OLD_DEFAULTS)
  32. assert not any(key.isupper() for key in _TO_OLD_KEY)
  33. assert not any(key.islower() for key in _TO_NEW_KEY)
  34. assert not any(key.isupper() for key in SETTING_KEYS)
  35. assert not any(key.islower() for key in _OLD_SETTING_KEYS)
  36. assert not any(value.isupper() for value in values(_TO_NEW_KEY))
  37. assert not any(value.islower() for value in values(_TO_OLD_KEY))
  38. for key in _TO_NEW_KEY:
  39. assert key in _OLD_SETTING_KEYS
  40. for key in _TO_OLD_KEY:
  41. assert key in SETTING_KEYS
  42. def test_find(self):
  43. find = self.defaults.find
  44. assert find('default_queue')[2].default == 'celery'
  45. assert find('task_default_exchange')[2] is None
  46. @property
  47. def defaults(self):
  48. return import_module('celery.app.defaults')