本文整理匯總了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])