本文整理汇总了Python中botocore.hooks.HierarchicalEmitter.unregister方法的典型用法代码示例。如果您正苦于以下问题:Python HierarchicalEmitter.unregister方法的具体用法?Python HierarchicalEmitter.unregister怎么用?Python HierarchicalEmitter.unregister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.hooks.HierarchicalEmitter
的用法示例。
在下文中一共展示了HierarchicalEmitter.unregister方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
class TestWildcardHandlers(unittest.TestCase):
def setUp(self):
self.emitter = HierarchicalEmitter()
self.hook_calls = []
def hook(self, **kwargs):
self.hook_calls.append(kwargs)
def register(self, event_name):
func = partial(self.hook, registered_with=event_name)
self.emitter.register(event_name, func)
return func
def assert_hook_is_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after > starting:
self.fail("Handler was not called for event: %s" % event)
self.assertEqual(self.hook_calls[-1]['event_name'], event)
def assert_hook_is_not_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after == starting:
self.fail("Handler was called for event but was not "
"suppose to be called: %s, last_event: %s" %
(event, self.hook_calls[-1]))
def test_one_level_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
# Also register for a number of other events to check
# for false positives.
self.emitter.register('other.bar.baz', self.hook)
self.emitter.register('qqq.baz', self.hook)
self.emitter.register('dont.call.me', self.hook)
self.emitter.register('dont', self.hook)
# These calls should trigger our hook.
self.assert_hook_is_called_given_event('foo.bar.baz')
self.assert_hook_is_called_given_event('foo.qux.baz')
self.assert_hook_is_called_given_event('foo.anything.baz')
# These calls should not match our hook.
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('bar.qux.baz')
self.assert_hook_is_not_called_given_event('foo-bar')
def test_hierarchical_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.qux')
self.assert_hook_is_called_given_event('foo.bar.baz.qux.foo')
self.assert_hook_is_called_given_event('foo.qux.baz.qux')
self.assert_hook_is_called_given_event('foo.qux.baz.qux.foo')
self.assert_hook_is_not_called_given_event('bar.qux.baz.foo')
def test_multiple_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.ANY.THING.baz')
self.assert_hook_is_called_given_event('foo.AT.ALL.baz')
# More specific than what we registered for.
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra')
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra.stuff')
# Too short:
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('foo.bar.baz')
# Bad ending segment.
self.assert_hook_is_not_called_given_event('foo.ANY.THING.notbaz')
self.assert_hook_is_not_called_given_event('foo.ANY.THING.stillnotbaz')
def test_can_unregister_for_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
# Call multiple times to verify caching behavior.
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
def test_unregister_does_not_exist(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
def test_cache_cleared_properly(self):
#.........这里部分代码省略.........
示例2: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
#.........这里部分代码省略.........
"""
log = logging.getLogger(logger_name)
log.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.FileHandler(path)
ch.setLevel(log_level)
# create formatter
formatter = logging.Formatter(self.FmtString)
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)
def register(self, event_name, handler, unique_id=None,
unique_id_uses_count=False):
"""Register a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to invoke when the event
is emitted. This object must be callable, and must
accept ``**kwargs``. If either of these preconditions are
not met, a ``ValueError`` will be raised.
:type unique_id: str
:param unique_id: An optional identifier to associate with the
registration. A unique_id can only be used once for
the entire session registration (unless it is unregistered).
This can be used to prevent an event handler from being
registered twice.
:param unique_id_uses_count: boolean
:param unique_id_uses_count: Specifies if the event should maintain
a count when a ``unique_id`` is registered and unregisted. The
event can only be completely unregistered once every register call
using the unique id has been matched by an ``unregister`` call.
If ``unique_id`` is specified, subsequent ``register``
calls must use the same value for ``unique_id_uses_count``
as the ``register`` call that first registered the event.
:raises ValueError: If the call to ``register`` uses ``unique_id``
but the value for ``unique_id_uses_count`` differs from the
``unique_id_uses_count`` value declared by the very first
``register`` call for that ``unique_id``.
"""
self._events.register(event_name, handler, unique_id,
unique_id_uses_count=unique_id_uses_count)
def unregister(self, event_name, handler=None, unique_id=None,
unique_id_uses_count=False):
"""Unregister a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to unregister.
:type unique_id: str
:param unique_id: A unique identifier identifying the callback
示例3: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
#.........这里部分代码省略.........
if it doesn't already exist.
"""
log = logging.getLogger(logger_name)
log.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.FileHandler(path)
ch.setLevel(log_level)
# create formatter
formatter = logging.Formatter(self.LOG_FORMAT)
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)
def register(self, event_name, handler, unique_id=None, unique_id_uses_count=False):
"""Register a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to invoke when the event
is emitted. This object must be callable, and must
accept ``**kwargs``. If either of these preconditions are
not met, a ``ValueError`` will be raised.
:type unique_id: str
:param unique_id: An optional identifier to associate with the
registration. A unique_id can only be used once for
the entire session registration (unless it is unregistered).
This can be used to prevent an event handler from being
registered twice.
:param unique_id_uses_count: boolean
:param unique_id_uses_count: Specifies if the event should maintain
a count when a ``unique_id`` is registered and unregisted. The
event can only be completely unregistered once every register call
using the unique id has been matched by an ``unregister`` call.
If ``unique_id`` is specified, subsequent ``register``
calls must use the same value for ``unique_id_uses_count``
as the ``register`` call that first registered the event.
:raises ValueError: If the call to ``register`` uses ``unique_id``
but the value for ``unique_id_uses_count`` differs from the
``unique_id_uses_count`` value declared by the very first
``register`` call for that ``unique_id``.
"""
self._events.register(event_name, handler, unique_id, unique_id_uses_count=unique_id_uses_count)
def unregister(self, event_name, handler=None, unique_id=None, unique_id_uses_count=False):
"""Unregister a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to unregister.
:type unique_id: str
:param unique_id: A unique identifier identifying the callback
to unregister. You can provide either the handler or the
unique_id, you do not have to provide both.
示例4: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
#.........这里部分代码省略.........
if it doesn't already exist.
"""
log = logging.getLogger(logger_name)
log.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.FileHandler(path)
ch.setLevel(log_level)
# create formatter
formatter = logging.Formatter(self.FmtString)
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)
def register(self, event_name, handler, unique_id=None):
"""Register a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to invoke when the event
is emitted. This object must be callable, and must
accept ``**kwargs``. If either of these preconditions are
not met, a ``ValueError`` will be raised.
:type unique_id: str
:param unique_id: An optional identifier to associate with the
registration. A unique_id can only be used once for
the entire session registration (unless it is unregistered).
This can be used to prevent an event handler from being
registered twice.
"""
self._events.register(event_name, handler, unique_id)
def unregister(self, event_name, handler=None, unique_id=None):
"""Unregister a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to unregister.
:type unique_id: str
:param unique_id: A unique identifier identifying the callback
to unregister. You can provide either the handler or the
unique_id, you do not have to provide both.
"""
self._events.unregister(event_name, handler=handler,
unique_id=unique_id)
def register_event(self, event_name, fmtstr):
"""
Register a new event. The event will be added to ``AllEvents``
and will then be able to be created using ``create_event``.
:type event_name: str
:param event_name: The base name of the event.
示例5: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
class TestWildcardHandlers(unittest.TestCase):
def setUp(self):
self.emitter = HierarchicalEmitter()
self.hook_calls = []
def hook(self, **kwargs):
self.hook_calls.append(kwargs)
def register(self, event_name):
func = partial(self.hook, registered_with=event_name)
self.emitter.register(event_name, func)
return func
def assert_hook_is_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after > starting:
self.fail("Handler was not called for event: %s" % event)
self.assertEqual(self.hook_calls[-1]['event_name'], event)
def assert_hook_is_not_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after == starting:
self.fail("Handler was called for event but was not "
"suppose to be called: %s, last_event: %s" %
(event, self.hook_calls[-1]))
def test_one_level_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
# Also register for a number of other events to check
# for false positives.
self.emitter.register('other.bar.baz', self.hook)
self.emitter.register('qqq.baz', self.hook)
self.emitter.register('dont.call.me', self.hook)
self.emitter.register('dont', self.hook)
# These calls should trigger our hook.
self.assert_hook_is_called_given_event('foo.bar.baz')
self.assert_hook_is_called_given_event('foo.qux.baz')
self.assert_hook_is_called_given_event('foo.anything.baz')
# These calls should not match our hook.
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('bar.qux.baz')
self.assert_hook_is_not_called_given_event('foo-bar')
def test_hierarchical_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.qux')
self.assert_hook_is_called_given_event('foo.bar.baz.qux.foo')
self.assert_hook_is_called_given_event('foo.qux.baz.qux')
self.assert_hook_is_called_given_event('foo.qux.baz.qux.foo')
self.assert_hook_is_not_called_given_event('bar.qux.baz.foo')
def test_multiple_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.ANY.THING.baz')
self.assert_hook_is_called_given_event('foo.AT.ALL.baz')
# More specific than what we registered for.
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra')
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra.stuff')
# Too short:
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('foo.bar.baz')
# Bad ending segment.
self.assert_hook_is_not_called_given_event('foo.ANY.THING.notbaz')
self.assert_hook_is_not_called_given_event('foo.ANY.THING.stillnotbaz')
def test_can_unregister_for_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
# Call multiple times to verify caching behavior.
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
def test_unregister_does_not_exist(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
def test_cache_cleared_properly(self):
#.........这里部分代码省略.........
示例6: Session
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
#.........这里部分代码省略.........
if it doesn't already exist.
"""
log = logging.getLogger(logger_name)
log.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.FileHandler(path)
ch.setLevel(log_level)
# create formatter
formatter = logging.Formatter(self.FmtString)
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
log.addHandler(ch)
def register(self, event_name, handler, unique_id=None):
"""Register a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to invoke when the event
is emitted. This object must be callable, and must
accept ``**kwargs``. If either of these preconditions are
not met, a ``ValueError`` will be raised.
:type unique_id: str
:param unique_id: An optional identifier to associate with the
registration. A unique_id can only be used once for
the entire session registration (unless it is unregistered).
This can be used to prevent an event handler from being
registered twice.
"""
self._events.register(event_name, handler, unique_id)
def unregister(self, event_name, handler=None, unique_id=None):
"""Unregister a handler with an event.
:type event_name: str
:param event_name: The name of the event.
:type handler: callable
:param handler: The callback to unregister.
:type unique_id: str
:param unique_id: A unique identifier identifying the callback
to unregister. You can provide either the handler or the
unique_id, you do not have to provide both.
"""
self._events.unregister(event_name, handler=handler,
unique_id=unique_id)
def register_event(self, event_name, fmtstr):
"""
Register a new event. The event will be added to ``AllEvents``
and will then be able to be created using ``create_event``.
:type event_name: str
:param event_name: The base name of the event.
示例7: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
class TestWildcardHandlers(unittest.TestCase):
def setUp(self):
self.emitter = HierarchicalEmitter()
self.hook_calls = []
def hook(self, **kwargs):
self.hook_calls.append(kwargs)
def register(self, event_name):
func = partial(self.hook, registered_with=event_name)
self.emitter.register(event_name, func)
return func
def assert_hook_is_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after > starting:
self.fail("Handler was not called for event: %s" % event)
self.assertEqual(self.hook_calls[-1]['event_name'], event)
def assert_hook_is_not_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after == starting:
self.fail("Handler was called for event but was not "
"suppose to be called: %s, last_event: %s" %
(event, self.hook_calls[-1]))
def test_one_level_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
# Also register for a number of other events to check
# for false positives.
self.emitter.register('other.bar.baz', self.hook)
self.emitter.register('qqq.baz', self.hook)
self.emitter.register('dont.call.me', self.hook)
self.emitter.register('dont', self.hook)
# These calls should trigger our hook.
self.assert_hook_is_called_given_event('foo.bar.baz')
self.assert_hook_is_called_given_event('foo.qux.baz')
self.assert_hook_is_called_given_event('foo.anything.baz')
# These calls should not match our hook.
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('bar.qux.baz')
self.assert_hook_is_not_called_given_event('foo-bar')
def test_hierarchical_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.qux')
self.assert_hook_is_called_given_event('foo.bar.baz.qux.foo')
self.assert_hook_is_called_given_event('foo.qux.baz.qux')
self.assert_hook_is_called_given_event('foo.qux.baz.qux.foo')
self.assert_hook_is_not_called_given_event('bar.qux.baz.foo')
def test_multiple_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.ANY.THING.baz')
self.assert_hook_is_called_given_event('foo.AT.ALL.baz')
# More specific than what we registered for.
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra')
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra.stuff')
# Too short:
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('foo.bar.baz')
# Bad ending segment.
self.assert_hook_is_not_called_given_event('foo.ANY.THING.notbaz')
self.assert_hook_is_not_called_given_event('foo.ANY.THING.stillnotbaz')
def test_can_unregister_for_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
# Call multiple times to verify caching behavior.
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
def test_unregister_does_not_exist(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
def test_cache_cleared_properly(self):
#.........这里部分代码省略.........
示例8: TestWildcardHandlers
# 需要导入模块: from botocore.hooks import HierarchicalEmitter [as 别名]
# 或者: from botocore.hooks.HierarchicalEmitter import unregister [as 别名]
class TestWildcardHandlers(unittest.TestCase):
def setUp(self):
self.emitter = HierarchicalEmitter()
self.hook_calls = []
def hook(self, **kwargs):
self.hook_calls.append(kwargs)
def register(self, event_name):
func = partial(self.hook, registered_with=event_name)
self.emitter.register(event_name, func)
return func
def assert_hook_is_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after > starting:
self.fail("Handler was not called for event: %s" % event)
self.assertEqual(self.hook_calls[-1]['event_name'], event)
def assert_hook_is_not_called_given_event(self, event):
starting = len(self.hook_calls)
self.emitter.emit(event)
after = len(self.hook_calls)
if not after == starting:
self.fail("Handler was called for event but was not "
"suppose to be called: %s, last_event: %s" %
(event, self.hook_calls[-1]))
def test_one_level_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
# Also register for a number of other events to check
# for false positives.
self.emitter.register('other.bar.baz', self.hook)
self.emitter.register('qqq.baz', self.hook)
self.emitter.register('dont.call.me', self.hook)
self.emitter.register('dont', self.hook)
# These calls should trigger our hook.
self.assert_hook_is_called_given_event('foo.bar.baz')
self.assert_hook_is_called_given_event('foo.qux.baz')
self.assert_hook_is_called_given_event('foo.anything.baz')
# These calls should not match our hook.
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('bar.qux.baz')
self.assert_hook_is_not_called_given_event('foo-bar')
def test_hierarchical_wildcard_handler(self):
self.emitter.register('foo.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.qux')
self.assert_hook_is_called_given_event('foo.bar.baz.qux.foo')
self.assert_hook_is_called_given_event('foo.qux.baz.qux')
self.assert_hook_is_called_given_event('foo.qux.baz.qux.foo')
self.assert_hook_is_not_called_given_event('bar.qux.baz.foo')
def test_multiple_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.ANY.THING.baz')
self.assert_hook_is_called_given_event('foo.AT.ALL.baz')
# More specific than what we registered for.
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra')
self.assert_hook_is_called_given_event('foo.bar.baz.baz.extra.stuff')
# Too short:
self.assert_hook_is_not_called_given_event('foo')
self.assert_hook_is_not_called_given_event('foo.bar')
self.assert_hook_is_not_called_given_event('foo.bar.baz')
# Bad ending segment.
self.assert_hook_is_not_called_given_event('foo.ANY.THING.notbaz')
self.assert_hook_is_not_called_given_event('foo.ANY.THING.stillnotbaz')
def test_can_unregister_for_wildcard_events(self):
self.emitter.register('foo.*.*.baz', self.hook)
# Call multiple times to verify caching behavior.
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
self.emitter.register('foo.*.*.baz', self.hook)
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
self.assert_hook_is_called_given_event('foo.bar.baz.baz')
def test_unregister_does_not_exist(self):
self.emitter.register('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.emitter.unregister('foo.*.*.baz', self.hook)
self.assert_hook_is_not_called_given_event('foo.bar.baz.baz')
def test_cache_cleared_properly(self):
#.........这里部分代码省略.........