test_defaults.py 2.0 KB

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