def __init__(self, config=None): if config is None: config = Config() if not isinstance(config, Config): raise TypeError self.config = config self.extensions = {}
def test_from_pyfile(self): """Config is loaded from Python file""" dirname = os.path.dirname(__file__) path = os.path.join(dirname, 'config.py') config = Config() config.from_pyfile(path) self.assertEqual(config.WORKER_MAX_LOAD, 20)
def test_from_env_vars(self): """Config is laoded from environment variables""" os.environ['KUYRUK_WORKER_MAX_LOAD'] = '21' try: config = Config() config.from_env_vars() self.assertEqual(config.WORKER_MAX_LOAD, 21) finally: del os.environ['KUYRUK_WORKER_MAX_LOAD']
return 1 / 0 @kuyruk.task(retry=1) def retry_task(): return 1 / 0 @kuyruk.task def loop_forever(): while 1: print('looping forever') sleep(1) config_eager = Config() config_eager.EAGER = True kuyruk_eager = Kuyruk(config_eager) @kuyruk_eager.task() def eager_task(): must_be_called() @kuyruk.task def rejecting_task(): raise kuyruk.Reject @kuyruk.task(max_run_time=1)
def test_from_config(self): """Config is loaded from dict""" config = Config() config.from_dict({'WORKER_MAX_LOAD': 21}) self.assertEqual(config.WORKER_MAX_LOAD, 21)
def test_from_object(self): """Config is loaded from Python object""" user_config.WORKER_MAX_LOAD = 21 config = Config() config.from_object(user_config) self.assertEqual(config.WORKER_MAX_LOAD, 21)
def test_from_pymodule(self): """Config is loaded from Python module""" config = Config() config.from_pymodule('config2') self.assertEqual(config.WORKER_MAX_LOAD, 20)
def __init__(self, config: Config = None) -> None: if config is None: config = Config() self.config = config self.extensions = {} # type: Dict[str, Any]
def test_from_object(self): user_config.WORKER_MAX_LOAD = 21 config = Config() config.from_object(user_config) self.assertEqual(config.WORKER_MAX_LOAD, 21)
def test_from_pymodule(self): config = Config() config.from_pymodule('config2') self.assertEqual(config.WORKER_MAX_LOAD, 20)