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
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)
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)
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
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)
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
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
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)
def test_set_exception_special_banned_exceptions(): """ Exceptions with special significant to StatusBase are banned. See comments in set_exception. """ st = StatusBase() # Test the class and the instance of each. with pytest.raises(ValueError): st.set_exception(StatusTimeoutError) with pytest.raises(ValueError): st.set_exception(StatusTimeoutError()) with pytest.raises(ValueError): st.set_exception(WaitTimeoutError) with pytest.raises(ValueError): st.set_exception(WaitTimeoutError())