test_defaults.py 1.9 KB

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