Exemplo n.º 1
0
def test_use_connection_explicit_redis(redis, loop):
    """Pass redis connection explicitly."""

    connection = yield from find_connection(loop)
    yield from use_connection(redis=connection)
    assert get_current_connection() == connection
    push_connection(redis)      # Make test finalizer happy.
Exemplo n.º 2
0
def test_use_connection_cleanup_stack(redis, loop):
    """Ensure connection stack cleanup."""

    kwargs = dict(address=('localhost', 6379), loop=loop)
    yield from use_connection(**kwargs)
    assert len(_connection_stack) == 1
    push_connection(redis)      # Make test finalizer happy.
Exemplo n.º 3
0
def test_use_connection(redis, loop):
    """Replace connection stack."""

    kwargs = dict(address=('localhost', 6379), loop=loop)
    yield from use_connection(**kwargs)
    assert get_current_connection() != redis
    push_connection(redis)      # Make test finalizer happy.
Exemplo n.º 4
0
def test_connection_stacking_with_use_connection(redis, loop):
    """Disallow use of use_connection() together with stacked contexts."""

    kwargs = dict(address=('localhost', 6379), loop=loop)
    with pytest.raises(AssertionError):
        with (yield from Connection(**kwargs)):
            with (yield from Connection(**kwargs)):
                yield from use_connection(**kwargs)