当前位置: 首页>>代码示例>>Python>>正文


Python Emitter.emit方法代码示例

本文整理汇总了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
开发者ID:titouandk,项目名称:emitter.py,代码行数:11,代码来源:test-emitter.py

示例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()
开发者ID:titouandk,项目名称:emitter.py,代码行数:11,代码来源:test-emitter.py

示例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
开发者ID:titouandk,项目名称:emitter.py,代码行数:11,代码来源:test-emitter.py

示例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]
开发者ID:titouandk,项目名称:emitter.py,代码行数:12,代码来源:test-emitter.py

示例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")
开发者ID:titouandk,项目名称:emitter.py,代码行数:13,代码来源:test-emitter.py

示例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)
开发者ID:titouandk,项目名称:emitter.py,代码行数:13,代码来源:test-error-handling.py

示例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]
开发者ID:titouandk,项目名称:emitter.py,代码行数:13,代码来源:test-emitter.py

示例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")
开发者ID:titouandk,项目名称:emitter.py,代码行数:13,代码来源:test-emitter.py

示例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
开发者ID:titouandk,项目名称:emitter.py,代码行数:13,代码来源:test-emitter.py

示例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
开发者ID:titouandk,项目名称:emitter.py,代码行数:14,代码来源:test-emitter.py

示例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
开发者ID:titouandk,项目名称:emitter.py,代码行数:14,代码来源:test-emitter.py

示例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]
开发者ID:AjayMT,项目名称:emitter,代码行数:54,代码来源:emitter_test.py

示例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
开发者ID:titouandk,项目名称:emitter.py,代码行数:15,代码来源:test-error-handling.py

示例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)
开发者ID:titouandk,项目名称:emitter.py,代码行数:16,代码来源:test-error-handling.py

示例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")
开发者ID:titouandk,项目名称:emitter.py,代码行数:16,代码来源:test-emitter.py


注:本文中的emitter.Emitter.emit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。