本文整理汇总了Python中observable.Observable.off方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.off方法的具体用法?Python Observable.off怎么用?Python Observable.off使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类observable.Observable
的用法示例。
在下文中一共展示了Observable.off方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_event_for_trigger
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import off [as 别名]
def test_no_event_for_trigger():
"""test exception raising for not existing events"""
obs = Observable()
assert not obs.trigger("no_existing_event")
with pytest.raises(EventNotFound):
obs.off("no_existing_event")
示例2: test_off_multiple_handlers
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import off [as 别名]
def test_off_multiple_handlers():
"""test event unregistering with the off method and multiple handlers"""
obs = Observable()
results = []
def some_test(*args, **kw):
results.append(1)
def some_test_2(*args, **kw):
results.append(2)
obs.on("some_test", some_test, some_test_2)
assert len(obs._events["some_test"]) == 2
obs.off("some_test", some_test, some_test_2)
assert len(obs._events["some_test"]) == 0
assert not obs.trigger("some_test")
示例3: test_off_exceptions
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import off [as 别名]
def test_off_exceptions():
"""test exception raising in the off method"""
obs = Observable()
with pytest.raises(EventNotFound):
obs.off("non_existing_event")
@obs.on("some_event")
def some_assigned_handler():
pass
def some_non_assigned_handler():
pass
assert some_assigned_handler in obs._events["some_event"]
assert some_non_assigned_handler not in obs._events["some_event"]
with pytest.raises(HandlerNotFound):
obs.off("some_event", some_non_assigned_handler)
示例4: test_off
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import off [as 别名]
def test_off():
"""test obs.off method"""
obs = Observable()
@obs.on("on_test")
def on_test():
pass
assert obs._events["on_test"] == [on_test]
assert obs.trigger("on_test")
obs.off("on_test", on_test)
assert obs._events["on_test"] == []
obs.off()
assert not obs._events
@obs.on("more_than_one_event")
def func1():
pass
@obs.on("more_than_one_event")
def func2():
pass
@obs.on("more_than_one_event")
def func3():
pass
assert obs._events["more_than_one_event"] == [func1, func2, func3]
obs.off("more_than_one_event", func2)
assert obs._events["more_than_one_event"] == [func1, func3]
obs.off("more_than_one_event")
assert obs._events["more_than_one_event"] == []