예제 #1
0
def test_add_done_callback_pending_batch():
    future = Future()
    callback = mock.Mock()
    future.add_done_callback(callback)
    assert len(future._callbacks) == 1
    assert callback in future._callbacks
    assert callback.call_count == 0
예제 #2
0
def test_exception_with_error():
    future = Future()
    error = RuntimeError('Something really bad happened.')
    future.set_exception(error)

    # Make sure that the exception that is returned is the batch's error.
    # Also check the type to ensure the batch's error did not somehow
    # change internally.
    assert future.exception() is error
    assert isinstance(future.exception(), RuntimeError)
    with pytest.raises(RuntimeError):
        future.result()
예제 #3
0
def test_trigger():
    future = Future()
    callback = mock.Mock(spec=())
    future.add_done_callback(callback)
    assert callback.call_count == 0
    future.set_result('12345')
    callback.assert_called_once_with(future)
예제 #4
0
def test_add_done_callback_completed_batch():
    future = Future()
    future.set_result('12345')
    callback = mock.Mock(spec=())
    future.add_done_callback(callback)
    callback.assert_called_once_with(future)
예제 #5
0
def test_result_with_error():
    future = Future()
    future.set_exception(RuntimeError('Something really bad happened.'))
    with pytest.raises(RuntimeError):
        future.result()
예제 #6
0
def test_result_no_error():
    future = Future()
    future.set_result('42')
    assert future.result() == '42'
예제 #7
0
def test_exception_timeout():
    future = Future()
    with pytest.raises(exceptions.TimeoutError):
        future.exception(timeout=0.01)
예제 #8
0
def test_done():
    future = Future()
    assert future.done() is False
    future.set_result('12345')
    assert future.done() is True
예제 #9
0
def test_exception_no_error():
    future = Future()
    future.set_result('12345')
    assert future.exception() is None
예제 #10
0
def test_running():
    assert Future().running() is True
예제 #11
0
def test_cancelled():
    assert Future().cancelled() is False
예제 #12
0
def test_set_exception_once_only():
    future = Future()
    future.set_exception(ValueError('wah wah'))
    with pytest.raises(RuntimeError):
        future.set_exception(TypeError('other wah wah'))
예제 #13
0
def test_set_result_once_only():
    future = Future()
    future.set_result('12345')
    with pytest.raises(RuntimeError):
        future.set_result('67890')
예제 #14
0
def test_running():
    future = Future()
    assert future.running() is True
    future.set_result('foobar')
    assert future.running() is False