本文整理汇总了Python中botocore.hooks.HierarchicalEmitter.emit_until_response方法的典型用法代码示例。如果您正苦于以下问题:Python HierarchicalEmitter.emit_until_response方法的具体用法?Python HierarchicalEmitter.emit_until_response怎么用?Python HierarchicalEmitter.emit_until_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.hooks.HierarchicalEmitter
的用法示例。
在下文中一共展示了HierarchicalEmitter.emit_until_response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStopProcessing
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import emit_until_response [as 别名]
class TestStopProcessing(unittest.TestCase):
def setUp(self):
self.emitter = HierarchicalEmitter()
self.hook_calls = []
def hook1(self, **kwargs):
self.hook_calls.append('hook1')
def hook2(self, **kwargs):
self.hook_calls.append('hook2')
return 'hook2-response'
def hook3(self, **kwargs):
self.hook_calls.append('hook3')
return 'hook3-response'
def test_all_hooks(self):
# Here we register three hooks and sanity check
# that all three would be called by a normal emit.
# This ensures our hook calls are setup properly for
# later tests.
self.emitter.register('foo', self.hook1)
self.emitter.register('foo', self.hook2)
self.emitter.register('foo', self.hook3)
self.emitter.emit('foo')
self.assertEqual(self.hook_calls, ['hook1', 'hook2', 'hook3'])
def test_stop_processing_after_first_response(self):
# Here we register three hooks, but only the first
# two should ever execute.
self.emitter.register('foo', self.hook1)
self.emitter.register('foo', self.hook2)
self.emitter.register('foo', self.hook3)
handler, response = self.emitter.emit_until_response('foo')
self.assertEqual(response, 'hook2-response')
self.assertEqual(self.hook_calls, ['hook1', 'hook2'])
def test_no_responses(self):
# Here we register a handler that will not return a response
# and ensure we get back proper values.
self.emitter.register('foo', self.hook1)
responses = self.emitter.emit('foo')
self.assertEqual(self.hook_calls, ['hook1'])
self.assertEqual(responses, [(self.hook1, None)])
def test_no_handlers(self):
# Here we have no handlers, but still expect a tuple of return
# values.
handler, response = self.emitter.emit_until_response('foo')
self.assertIsNone(handler)
self.assertIsNone(response)