本文整理汇总了Python中charmhelpers.core.hookenv.Hooks方法的典型用法代码示例。如果您正苦于以下问题:Python hookenv.Hooks方法的具体用法?Python hookenv.Hooks怎么用?Python hookenv.Hooks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.hookenv
的用法示例。
在下文中一共展示了hookenv.Hooks方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_config_saved_after_execute
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_config_saved_after_execute(self):
config = hookenv.config()
config.implicit_save = True
foo = MagicMock()
hooks = hookenv.Hooks()
hooks.register('foo', foo)
hooks.execute(['foo', 'some', 'other', 'args'])
self.assertTrue(os.path.exists(config.path))
示例2: test_config_not_saved_after_execute
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_config_not_saved_after_execute(self):
config = hookenv.config()
config.implicit_save = False
foo = MagicMock()
hooks = hookenv.Hooks()
hooks.register('foo', foo)
hooks.execute(['foo', 'some', 'other', 'args'])
self.assertFalse(os.path.exists(config.path))
示例3: test_config_save_disabled
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_config_save_disabled(self):
config = hookenv.config()
config.implicit_save = True
foo = MagicMock()
hooks = hookenv.Hooks(config_save=False)
hooks.register('foo', foo)
hooks.execute(['foo', 'some', 'other', 'args'])
self.assertFalse(os.path.exists(config.path))
示例4: test_runs_a_registered_function
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_runs_a_registered_function(self):
foo = MagicMock()
hooks = hookenv.Hooks()
hooks.register('foo', foo)
hooks.execute(['foo', 'some', 'other', 'args'])
foo.assert_called_with()
示例5: test_cannot_run_unregistered_function
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_cannot_run_unregistered_function(self):
foo = MagicMock()
hooks = hookenv.Hooks()
hooks.register('foo', foo)
self.assertRaises(hookenv.UnregisteredHookError, hooks.execute,
['bar'])
示例6: test_can_run_a_decorated_function_as_itself
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_can_run_a_decorated_function_as_itself(self):
execs = []
hooks = hookenv.Hooks()
@hooks.hook()
def func():
execs.append(True)
hooks.execute(['func'])
self.assertRaises(hookenv.UnregisteredHookError, hooks.execute,
['brew'])
self.assertEqual(execs, [True])
示例7: test_magic_underscores
# 需要导入模块: from charmhelpers.core import hookenv [as 别名]
# 或者: from charmhelpers.core.hookenv import Hooks [as 别名]
def test_magic_underscores(self):
# Juju hook names use hypens as separators. Python functions use
# underscores. If explicit names have not been provided, hooks
# are registered with both the function name and the function
# name with underscores replaced with hypens for convenience.
execs = []
hooks = hookenv.Hooks()
@hooks.hook()
def call_me_maybe():
execs.append(True)
hooks.execute(['call-me-maybe'])
hooks.execute(['call_me_maybe'])
self.assertEqual(execs, [True, True])