本文整理汇总了Python中celery.loaders.app.AppLoader.config_from_envvar方法的典型用法代码示例。如果您正苦于以下问题:Python AppLoader.config_from_envvar方法的具体用法?Python AppLoader.config_from_envvar怎么用?Python AppLoader.config_from_envvar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.loaders.app.AppLoader
的用法示例。
在下文中一共展示了AppLoader.config_from_envvar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_AppLoader
# 需要导入模块: from celery.loaders.app import AppLoader [as 别名]
# 或者: from celery.loaders.app.AppLoader import config_from_envvar [as 别名]
class test_AppLoader(unittest.TestCase):
def setUp(self):
self.app = app_or_default()
self.loader = AppLoader(app=self.app)
def test_config_from_envvar(self, key="CELERY_HARNESS_CFG1"):
self.assertFalse(self.loader.config_from_envvar("HDSAJIHWIQHEWQU",
silent=True))
self.assertRaises(ImproperlyConfigured,
self.loader.config_from_envvar, "HDSAJIHWIQHEWQU",
silent=False)
os.environ[key] = __name__ + ".object_config"
self.assertTrue(self.loader.config_from_envvar(key))
self.assertEqual(self.loader.conf["FOO"], 1)
self.assertEqual(self.loader.conf["BAR"], 2)
os.environ[key] = "unknown_asdwqe.asdwqewqe"
self.assertRaises(ImportError,
self.loader.config_from_envvar, key, silent=False)
self.assertFalse(self.loader.config_from_envvar(key, silent=True))
os.environ[key] = __name__ + ".dict_config"
self.assertTrue(self.loader.config_from_envvar(key))
self.assertEqual(self.loader.conf["FOO"], 10)
self.assertEqual(self.loader.conf["BAR"], 20)
def test_on_worker_init(self):
self.loader.conf["CELERY_IMPORTS"] = ("subprocess", )
sys.modules.pop("subprocess", None)
self.loader.on_worker_init()
self.assertIn("subprocess", sys.modules)
示例2: test_AppLoader
# 需要导入模块: from celery.loaders.app import AppLoader [as 别名]
# 或者: from celery.loaders.app.AppLoader import config_from_envvar [as 别名]
class test_AppLoader(Case):
def setUp(self):
self.app = app_or_default()
self.loader = AppLoader(app=self.app)
def test_config_from_envvar(self, key='CELERY_HARNESS_CFG1'):
self.assertFalse(self.loader.config_from_envvar('HDSAJIHWIQHEWQU',
silent=True))
with self.assertRaises(ImproperlyConfigured):
self.loader.config_from_envvar('HDSAJIHWIQHEWQU', silent=False)
os.environ[key] = __name__ + '.object_config'
self.assertTrue(self.loader.config_from_envvar(key))
self.assertEqual(self.loader.conf['FOO'], 1)
self.assertEqual(self.loader.conf['BAR'], 2)
os.environ[key] = 'unknown_asdwqe.asdwqewqe'
with self.assertRaises(ImportError):
self.loader.config_from_envvar(key, silent=False)
self.assertFalse(self.loader.config_from_envvar(key, silent=True))
os.environ[key] = __name__ + '.dict_config'
self.assertTrue(self.loader.config_from_envvar(key))
self.assertEqual(self.loader.conf['FOO'], 10)
self.assertEqual(self.loader.conf['BAR'], 20)
def test_on_worker_init(self):
prev, self.app.conf.CELERY_IMPORTS = \
self.app.conf.CELERY_IMPORTS, ('subprocess', )
try:
sys.modules.pop('subprocess', None)
self.loader.init_worker()
self.assertIn('subprocess', sys.modules)
finally:
self.app.conf.CELERY_IMPORTS = prev