示例#1
0
def test_base_hooks_pool_merge(mocker):
    callback0, callback1 = mocker.stub(), mocker.stub()
    hp0, hp1 = HooksPool(), HooksPool()
    hp0.subscribe(callback0, _Hook)
    hp1.subscribe(callback1, _Hook)

    hp0.merge(hp1)
    assert hp0.hooks[_Hook][0].callbacks == {callback0, callback1}
示例#2
0
def test_base_hooks_pool_subscribe_listen(mocker):
    callback = mocker.stub()
    hp = HooksPool(listen=True)
    hp.subscribe(callback, TestHook)
    assert isinstance(hp.hooks[TestHook][0], TestHook)
    try:
        threading.Thread(target=hp.start).start()
        time.sleep(0.1)
        callback.assert_called_once_with()
    finally:
        hp.stop()
示例#3
0
def test_base_hooks_pool_subscribe(mocker):
    callback = mocker.stub()
    hp = HooksPool()
    hp.subscribe(callback, _Hook)
    assert isinstance(hp.hooks[_Hook][0], _Hook)
    assert hp.hooks[_Hook][0].callbacks == {callback, }