Ejemplo n.º 1
0
def test_wait_timeout():
    """
    A WaitTimeoutError is raised when we block on wait(TIMEOUT) or
    exception(TIMEOUT) and the Status has not finished.
    """
    st = StatusBase()
    with pytest.raises(WaitTimeoutError):
        st.wait(0.01)
    with pytest.raises(WaitTimeoutError):
        st.exception(0.01)
Ejemplo n.º 2
0
def test_set_finished_after_timeout():
    """
    If an external callback (e.g. pyepics) calls set_finished after the status
    has timed out, ignore it.
    """
    st = StatusBase(timeout=0)
    time.sleep(0.1)
    assert isinstance(st.exception(), StatusTimeoutError)
    # External callback fires, too late.
    st.set_finished()
    assert isinstance(st.exception(), StatusTimeoutError)
Ejemplo n.º 3
0
def test_status_timeout_with_settle_time():
    """
    A StatusTimeoutError is raised when the timeout set in __init__ plus the
    settle_time has expired.
    """
    st = StatusBase(timeout=0, settle_time=1)
    # Not dead yet.
    with pytest.raises(WaitTimeoutError):
        st.exception(0.01)
    # But now we are.
    with pytest.raises(StatusTimeoutError):
        st.wait(2)
Ejemplo n.º 4
0
def test_set_exception_after_timeout():
    """
    If an external callback (e.g. pyepics) calls set_exception after the status
    has timed out, ignore it.
    """
    st = StatusBase(timeout=0)
    time.sleep(0.1)
    assert isinstance(st.exception(), StatusTimeoutError)

    class LocalException(Exception):
        ...

    # External callback reports failure, too late.
    st.set_exception(LocalException())
    assert isinstance(st.exception(), StatusTimeoutError)
Ejemplo n.º 5
0
def test_status_timeout():
    """
    A StatusTimeoutError is raised when the timeout set in __init__ has
    expired.
    """
    st = StatusBase(timeout=0)
    with pytest.raises(StatusTimeoutError):
        st.wait(1)
    assert isinstance(st.exception(), StatusTimeoutError)
Ejemplo n.º 6
0
def test_exception_fail_path():
    st = StatusBase()

    class LocalException(Exception):
        ...

    exc = LocalException()
    st.set_exception(exc)
    assert exc is st.exception()
    with pytest.raises(LocalException):
        st.wait(1)
Ejemplo n.º 7
0
def test_exception_fail_path_with_class():
    """
    Python allows `raise Exception` and `raise Exception()` so we do as well.
    """
    st = StatusBase()

    class LocalException(Exception):
        ...

    st.set_exception(LocalException)
    assert LocalException is st.exception()
    with pytest.raises(LocalException):
        st.wait(1)
Ejemplo n.º 8
0
def test_exception_success_path():
    st = StatusBase()
    st.set_finished()
    assert st.wait(1) is None
    assert st.exception() is None