Exemplo n.º 1
0
def test_and():
    st1 = StatusBase()
    st2 = StatusBase()
    st3 = st1 & st2
    # make sure deep recursion works
    st4 = st1 & st3
    st5 = st3 & st4
    state1, cb1 = _setup_state_and_cb()
    state2, cb2 = _setup_state_and_cb()
    state3, cb3 = _setup_state_and_cb()
    state4, cb4 = _setup_state_and_cb()
    state5, cb5 = _setup_state_and_cb()
    st1.add_callback(cb1)
    st2.add_callback(cb2)
    st3.add_callback(cb3)
    st4.add_callback(cb4)
    st5.add_callback(cb5)
    st1._finished()
    assert 'done' in state1
    assert 'done' not in state2
    assert 'done' not in state3
    assert 'done' not in state4
    assert 'done' not in state5
    st2._finished()
    assert 'done' in state3
    assert 'done' in state4
    assert 'done' in state5
    assert st3.left is st1
    assert st3.right is st2
    assert st4.left is st1
    assert st4.right is st3
    assert st5.left is st3
    assert st5.right is st4
Exemplo n.º 2
0
def test_status_legacy_finished_cb():
    st = StatusBase()
    state1, cb1 = _setup_state_and_cb()
    state2, cb2 = _setup_state_and_cb()

    # The old setter works for adding one callback.
    with pytest.warns(UserWarning):
        st.finished_cb = cb1
    # The new getter works.
    st.callbacks == set([cb1])
    # And the old getter works so long as there is just one callback set.
    with pytest.warns(UserWarning):
        assert st.finished_cb is cb1
    # As before, the old setter cannot be updated once set.
    with pytest.raises(UseNewProperty):
        st.finished_cb = cb2
    # But, using the new method, we can add another callback.
    st.add_callback(cb2)
    # Once we have two callbacks, the getter does not work.
    with pytest.raises(UseNewProperty):
        st.finished_cb
    # But the new getter does.
    st.callbacks == set([cb1, cb2])

    assert 'done' not in state1
    assert 'done' not in state2
    st._finished()
    assert 'done' in state1
    assert 'done' in state2
Exemplo n.º 3
0
def test_old_signature_on_finished_status():
    st = StatusBase()
    state, cb = _setup_state_and_cb(new_signature=False)
    st.set_finished()
    st.wait(1)
    with pytest.warns(DeprecationWarning, match="signature"):
        st.add_callback(cb)
    assert state
Exemplo n.º 4
0
def test_status_pre():
    st = StatusBase()
    state, cb = _setup_state_and_cb()

    st._finished()

    assert 'done' not in state
    st.add_callback(cb)
    assert 'done' in state
    assert state['done']
Exemplo n.º 5
0
def test_status_callback():
    "The new way, with add_callback and the callbacks property"
    st = StatusBase()
    cb = Mock()

    st.add_callback(cb)
    assert st.callbacks[0] is cb

    st._finished()
    cb.assert_called_once_with()
Exemplo n.º 6
0
def test_old_signature():
    st = StatusBase()
    state, cb = _setup_state_and_cb(new_signature=False)
    with pytest.warns(DeprecationWarning, match="signature"):
        st.add_callback(cb)
    assert not state
    st.set_finished()
    st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.
    assert state
Exemplo n.º 7
0
def test_old_finished_method_success():
    st = StatusBase()
    state, cb = _setup_state_and_cb()
    st.add_callback(cb)
    assert not state
    st._finished()
    st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.
    assert state
    assert st.done
    assert st.success
Exemplo n.º 8
0
def test_status_callback():
    "The new way, with add_callback and the callbacks property"
    st = StatusBase()
    cb = Mock()

    st.add_callback(cb)
    assert st.callbacks[0] is cb

    st.set_finished()
    st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.
    cb.assert_called_once_with(st)
Exemplo n.º 9
0
def test_status_pre():
    st = StatusBase()
    state, cb = _setup_state_and_cb()

    st.set_finished()
    st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.

    assert 'done' not in state
    st.add_callback(cb)
    assert 'done' in state
    assert state['done']
Exemplo n.º 10
0
def test_old_finished_method_failure():
    st = StatusBase()
    state, cb = _setup_state_and_cb()
    st.add_callback(cb)
    assert not state
    st._finished(success=False)
    with pytest.raises(UnknownStatusFailure):
        st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.
    assert state
    assert st.done
    assert not st.success