本文整理汇总了Python中emitter.Emitter.listeners方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter.listeners方法的具体用法?Python Emitter.listeners怎么用?Python Emitter.listeners使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emitter.Emitter
的用法示例。
在下文中一共展示了Emitter.listeners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listeners__6
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_listeners__6():
"""
Should not return the original object, but a copy.
"""
emitter = Emitter()
emitter.on("event", callable)
assert emitter.listeners("event") is not emitter.listeners("event")
示例2: test_listeners__1
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_listeners__1():
"""
Returns an empty list when asking for an unknown event.
"""
emitter = Emitter()
assert isinstance(emitter.listeners(""), list)
assert emitter.listeners("") == []
示例3: test_off__6
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_off__6():
"""
A listener of the False event can be removed.
"""
emitter = Emitter()
emitter.on(False, callable)
assert callable in emitter.listeners(False)
emitter.off(False, callable)
assert callable not in emitter.listeners(False)
示例4: test_off__7
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_off__7():
"""
A listener of the True event can be removed.
"""
emitter = Emitter()
emitter.on(True, callable)
assert callable in emitter.listeners(True)
emitter.off(True, callable)
assert callable not in emitter.listeners(True)
示例5: test_once__2
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_once__2():
"""
Listener should be removed after call.
"""
emitter = Emitter()
emitter.once("event", callable)
emitter.on("event", bool)
emitter.emit("event")
assert callable not in emitter.listeners("event")
assert bool in emitter.listeners("event")
示例6: test_on__7
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_on__7():
"""
Multiple listeners can be registered for an event.
"""
emitter = Emitter()
emitter.on("event", callable)
emitter.on("event", bool)
assert callable in emitter.listeners("event")
assert bool in emitter.listeners("event")
示例7: TestEmitter
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
class TestEmitter(TestCase):
def setUp(self):
self.emitter = Emitter()
def test_call_listeners(self):
called = [False]
def cb():
called[0] = True
self.emitter.on('hello.*', cb)
self.emitter.emit('hello.foo')
assert called[0]
self.emitter.remove('hello.*', cb)
assert self.emitter.listeners('hello') == []
def test_pass_data_to_listeners(self):
def cb(*args):
assert args == ('a', 'b')
self.emitter.on('data', cb)
self.emitter.emit('data', 'a', 'b')
def test_call_listeners_once(self):
called = [False]
def cb():
called[0] = not called[0]
self.emitter.on('once', cb, True)
self.emitter.emit('*')
self.emitter.emit('on*')
assert called[0]
def test_remove_listeners(self):
self.emitter.on('foo', lambda x: x)
self.emitter.on('bar', lambda x: x)
self.emitter.remove('bar')
self.emitter.remove('*')
assert self.emitter.listeners('foo') == []
assert self.emitter.listeners('bar') == []
def test_emit_unknown_events(self):
self.emitter.emit('quux')
self.emitter.remove('wut')
def test_provide_listeners(self):
def cb(): pass
self.emitter.on('quux', cb)
assert self.emitter.listeners('*') == [cb]
示例8: test_error__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_error__4(spy):
"""
One time listener is removed even if it raises exception.
"""
emitter = Emitter()
emitter.once("event", raise_error)
assert len(emitter.listeners("event")) == 1
emitter.emit("event")
assert len(emitter.listeners("event")) == 0
示例9: test_on__8
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_on__8():
"""
Listeners are not shared between events.
"""
emitter = Emitter()
emitter.on("event1", str)
emitter.on("event2", callable)
assert str in emitter.listeners("event1")
assert str not in emitter.listeners("event2")
assert callable in emitter.listeners("event2")
assert callable not in emitter.listeners("event1")
示例10: test_off__2
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_off__2():
"""
When called with 1 argument, it removes only the listeners of the
specified event.
"""
emitter = Emitter()
emitter.on("event", callable)
emitter.on("event", str)
emitter.on("raccoon", callable)
emitter.on("raccoon", str)
emitter.off("event")
assert emitter.listeners("event") == []
assert callable in emitter.listeners("raccoon")
assert str in emitter.listeners("raccoon")
示例11: test_error__5
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_error__5(spy):
"""
One time ERROR listener is removed even if it raises exception.
"""
emitter = Emitter()
emitter.once(Emitter.ERROR, spy.throw)
emitter.on("event", raise_error)
assert len(emitter.listeners(Emitter.ERROR)) == 1
with pytest.raises(Exception):
emitter.emit("event")
assert len(emitter.listeners(Emitter.ERROR)) == 0
示例12: test_on__9
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_on__9():
"""
Returns True when event has been successfully registered.
"""
emitter = Emitter()
assert emitter.on("event", callable) is True
assert callable in emitter.listeners("event")
示例13: test_listeners__5
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_listeners__5():
"""
Get the listeners for the True event.
"""
emitter = Emitter()
emitter.on(True, callable)
assert callable in emitter.listeners(True)
示例14: test_listeners__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_listeners__4():
"""
Get the listeners for the False event.
"""
emitter = Emitter()
emitter.on(False, callable)
assert callable in emitter.listeners(False)
示例15: test_once__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import listeners [as 别名]
def test_once__4():
"""
Allow updating an event from once() to on().
"""
emitter = Emitter()
emitter.on("event", callable)
emitter.once("event", callable)
emitter.emit("event")
assert callable not in emitter.listeners("event")