當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。