def test_unknown_value(self): with pytest.raises( TypeError, # todo replace below when dropping python 2.7 # match="Cannot coerce 'foo' to type bool"): match=r"Cannot coerce u?'foo' to type bool"): strtobool('foo')
def test_custom_table(self): custom_table = { 'foo': True, 'bar': False } assert strtobool("foo", table=custom_table) assert not strtobool("bar", table=custom_table)
def __init__(self, *args, **kwargs): super(RedisClusterBackend, self).__init__(expires_type=int, **kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass self.conn_params = self.app.conf.get( 'CELERY_REDIS_CLUSTER_SETTINGS', { 'startup_nodes': [{ 'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379 }] }) if self.conn_params is not None: if not isinstance(self.conn_params, dict): raise ImproperlyConfigured( 'RedisCluster backend settings should be grouped in a dict' ) try: new_join = strtobool(self.conn_params.pop('new_join')) if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return except KeyError: pass self.expires = self.prepare_expires(None, type=int) self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
def __init__(self, *args, **kwargs): super(RedisClusterBackend, self).__init__(expires_type=int, **kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass self.conn_params = self.app.conf.get('CELERY_REDIS_CLUSTER_SETTINGS', { 'startup_nodes': [{'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379}] }) if self.conn_params is not None: if not isinstance(self.conn_params, dict): raise ImproperlyConfigured( 'RedisCluster backend settings should be grouped in a dict') try: new_join = strtobool(self.conn_params.pop('new_join')) if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return except KeyError: pass self.expires = self.prepare_expires(None, type=int) self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
import os import warnings from celery.exceptions import NotConfigured from celery.utils.collections import DictAttribute from celery.utils.serialization import strtobool from .base import BaseLoader __all__ = ['Loader', 'DEFAULT_CONFIG_MODULE'] DEFAULT_CONFIG_MODULE = 'celeryconfig' #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False)) class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return DictAttribute(settingsdict) def read_configuration(self, fail_silently=True): """Read configuration from :file:`celeryconfig.py` and configure celery and Django so it can be used by regular Python.""" configname = os.environ.get('CELERY_CONFIG_MODULE', DEFAULT_CONFIG_MODULE) try: usercfg = self._import_config_module(configname) except ImportError:
def test_default_table(self, s, b): assert strtobool(s) == b
def test_no_op(self): assert strtobool(1) == 1
def test_unknown_value(self): with pytest.raises(TypeError, match="Cannot coerce 'foo' to type bool"): strtobool('foo')
import os import warnings from celery.exceptions import NotConfigured from celery.utils.collections import DictAttribute from celery.utils.serialization import strtobool from .base import BaseLoader __all__ = ["Loader", "DEFAULT_CONFIG_MODULE"] DEFAULT_CONFIG_MODULE = "celeryconfig" #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get("C_WNOCONF", False)) class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return DictAttribute(settingsdict) def read_configuration(self, fail_silently=True): """Read configuration from :file:`celeryconfig.py` and configure celery and Django so it can be used by regular Python.""" configname = os.environ.get("CELERY_CONFIG_MODULE", DEFAULT_CONFIG_MODULE) try: usercfg = self._import_config_module(configname) except ImportError:
import os import warnings from celery.exceptions import NotConfigured from celery.utils.collections import DictAttribute from celery.utils.serialization import strtobool from .base import BaseLoader __all__ = ("Loader", "DEFAULT_CONFIG_MODULE") DEFAULT_CONFIG_MODULE = "celeryconfig" #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get("C_WNOCONF", False)) class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return DictAttribute(settingsdict) def read_configuration(self, fail_silently=True): """Read configuration from :file:`celeryconfig.py`.""" configname = os.environ.get("CELERY_CONFIG_MODULE", DEFAULT_CONFIG_MODULE) try: usercfg = self._import_config_module(configname) except ImportError: if not fail_silently:
# -*- coding: utf-8 -*- """The default loader used when no custom app has been initialized.""" from __future__ import absolute_import, unicode_literals import os import warnings from celery.exceptions import NotConfigured from celery.utils.collections import DictAttribute from celery.utils.serialization import strtobool from .base import BaseLoader __all__ = ['Loader', 'DEFAULT_CONFIG_MODULE'] DEFAULT_CONFIG_MODULE = 'celeryconfig' #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False)) class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return DictAttribute(settingsdict) def read_configuration(self, fail_silently=True): """Read configuration from :file:`celeryconfig.py`.""" configname = os.environ.get('CELERY_CONFIG_MODULE', DEFAULT_CONFIG_MODULE) try: usercfg = self._import_config_module(configname) except ImportError:
def test_unknown_value(self): with pytest.raises(TypeError, # todo replace below when dropping python 2.7 # match="Cannot coerce 'foo' to type bool"): match=r"Cannot coerce u?'foo' to type bool"): strtobool('foo')