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


Python Emitter.once方法代码示例

本文整理汇总了Python中emitter.Emitter.once方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter.once方法的具体用法?Python Emitter.once怎么用?Python Emitter.once使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emitter.Emitter的用法示例。


在下文中一共展示了Emitter.once方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_once__3

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例2: test_once__4

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例3: test_once__2

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例4: test_once__1

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例5: test_error__4

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例6: test_once__5

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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

示例7: test_error__5

# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import once [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
开发者ID:titouandk,项目名称:emitter.py,代码行数:17,代码来源:test-error-handling.py


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