当前位置: 首页>>代码示例>>Python>>正文


Python hookenv.Hooks方法代码示例

本文整理汇总了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)) 
开发者ID:juju,项目名称:charm-helpers,代码行数:11,代码来源:test_hookenv.py

示例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)) 
开发者ID:juju,项目名称:charm-helpers,代码行数:11,代码来源:test_hookenv.py

示例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)) 
开发者ID:juju,项目名称:charm-helpers,代码行数:11,代码来源:test_hookenv.py

示例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() 
开发者ID:juju,项目名称:charm-helpers,代码行数:10,代码来源:test_hookenv.py

示例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']) 
开发者ID:juju,项目名称:charm-helpers,代码行数:9,代码来源:test_hookenv.py

示例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]) 
开发者ID:juju,项目名称:charm-helpers,代码行数:14,代码来源:test_hookenv.py

示例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]) 
开发者ID:juju,项目名称:charm-helpers,代码行数:17,代码来源:test_hookenv.py


注:本文中的charmhelpers.core.hookenv.Hooks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。