Esempio n. 1
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
Esempio n. 2
0
def test_status_callback():
    st = StatusBase()
    cb = Mock()

    st.finished_cb = cb
    assert st.finished_cb is cb
    with pytest.raises(RuntimeError):
        st.finished_cb = None

    st._finished()
    cb.assert_called_once_with()
Esempio n. 3
0
def test_status_callback():
    st = StatusBase()
    cb = Mock()

    st.finished_cb = cb
    assert st.finished_cb is cb
    with pytest.raises(RuntimeError):
        st.finished_cb = None

    st._finished()
    cb.assert_called_once_with()
Esempio n. 4
0
def test_status_callback_deprecated():
    "The old way, with finished_cb"
    st = StatusBase()
    cb = Mock()

    with pytest.warns(UserWarning):
        st.finished_cb = cb
    with pytest.warns(UserWarning):
        assert st.finished_cb is cb
    with pytest.raises(RuntimeError):
        st.finished_cb = None

    st._finished()
    cb.assert_called_once_with()
Esempio n. 5
0
def test_status_callback_deprecated():
    "The old way, with finished_cb"
    st = StatusBase()
    cb = Mock()

    with pytest.warns(UserWarning):
        st.finished_cb = cb
    with pytest.warns(UserWarning):
        assert st.finished_cb is cb
    with pytest.raises(RuntimeError):
        st.finished_cb = None

    st.set_finished()
    st.wait(1)
    time.sleep(0.1)  # Wait for callbacks to run.
    cb.assert_called_once_with(st)
Esempio n. 6
0
    def test_callback(self):
        st = StatusBase()
        cb = Mock()

        st.finished_cb = cb
        self.assertIs(st.finished_cb, cb)
        self.assertRaises(RuntimeError, setattr, st, 'finished_cb', None)

        st._finished()
        cb.assert_called_once_with()
Esempio n. 7
0
    def test_callback(self):
        st = StatusBase()
        cb = Mock()

        st.finished_cb = cb
        self.assertIs(st.finished_cb, cb)
        self.assertRaises(RuntimeError, setattr, st, 'finished_cb', None)

        st._finished()
        cb.assert_called_once_with()