本文整理汇总了Python中emitter.Emitter.emit方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter.emit方法的具体用法?Python Emitter.emit怎么用?Python Emitter.emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emitter.Emitter
的用法示例。
在下文中一共展示了Emitter.emit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_emit__7
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_emit__7():
"""
False event can be emitted.
"""
emitter = Emitter()
l = []
emitter.on(False, lambda: l.append(1))
emitter.emit(False)
assert 1 in l
示例2: test_once__3
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_once__3():
"""
Event should be cleaned if no more listeners.
"""
emitter = Emitter()
emitter.once("event", callable)
emitter.emit("event")
assert emitter.events() == set()
示例3: test_emit__8
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_emit__8():
"""
True event can be emitted.
"""
emitter = Emitter()
l = []
emitter.on(True, lambda: l.append(1))
emitter.emit(True)
assert 1 in l
示例4: test_emit__3
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_emit__3():
"""
Only the listeners of the specified event should be triggered.
"""
emitter = Emitter()
l = []
emitter.on("event1", lambda: l.append(1))
emitter.on("event2", lambda: l.append(2))
emitter.emit("event1")
assert l == [1]
示例5: test_once__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [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")
示例6: test_error__1
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_error__1(spy):
"""
ERROR event is emitted when some listener raises exception.
"""
emitter = Emitter()
emitter.on("event", raise_error)
emitter.on(Emitter.ERROR, spy)
emitter.emit("event")
assert spy.called(1)
示例7: test_emit__2
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_emit__2():
"""
Listeners are triggered in order of insertion.
"""
emitter = Emitter()
l = []
emitter.on("event", lambda: l.append(1))
emitter.on("event", lambda: l.append(2))
emitter.on("event", lambda: l.append(3))
emitter.emit("event")
assert l == [1, 2, 3]
示例8: test_once__2
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [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")
示例9: test_emit__1
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_emit__1():
"""
All the listeners of an event must be triggered.
"""
emitter = Emitter()
l = []
emitter.on("event", lambda: l.append(1))
emitter.on("event", lambda: l.append(1))
emitter.on("event", lambda: l.append(1))
emitter.emit("event")
assert len(l) == 3
示例10: test_once__1
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_once__1():
"""
Listener can be called only once.
"""
emitter = Emitter()
l = []
emitter.once("event", lambda: l.append(1))
emitter.emit("event")
emitter.emit("event")
emitter.emit("event")
assert len(l) == 1
示例11: test_on__11
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_on__11():
"""
One-shot listeners can be called only once.
"""
emitter = Emitter()
l = []
emitter.on("event", lambda: l.append(1), True)
emitter.emit("event")
emitter.emit("event")
emitter.emit("event")
assert len(l) == 1
示例12: TestEmitter
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [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]
示例13: test_error__4
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [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
示例14: test_error__3
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_error__3(spy):
"""
If error handler raises exception, it is re-raised, but not catched
by the emitter this time (no ERROR event this time).
"""
emitter = Emitter()
emitter.on("event", spy.throw)
emitter.on(Emitter.ERROR, spy.throw)
with pytest.raises(Exception):
emitter.emit("event")
assert spy.called(2)
示例15: test_once__5
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import emit [as 别名]
def test_once__5():
"""
One time listeners should be removed even if an error happens.
"""
emitter = Emitter()
def listener(*args, **kwargs):
raise Exception()
emitter.once("event", listener)
emitter.emit("event")
assert listener not in emitter.listeners("event")