# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: aredis/exceptions.py
# class WatchError(RedisError):
#     pass
# 
# class ResponseError(RedisError):
#     pass


import pytest
from aredis.utils import b
from aredis.exceptions import (WatchError,
                               ResponseError)
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_watch_succeed(self, r):
        await r.flushdb()
        await r.set('a', 1)
        await r.set('b', 2)

        async with await r.pipeline() as pipe:
            await pipe.watch('a', 'b')
            assert pipe.watching
            a_value = await pipe.get('a')
            b_value = await pipe.get('b')
            assert a_value == b('1')
            assert b_value == b('2')
            pipe.multi()

            await pipe.set('c', 3)
            assert await pipe.execute() == [True]
            assert not pipe.watching

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_watch_failure(self, r):
        await r.flushdb()
        await r.set('a', 1)
        await r.set('b', 2)

        async with await r.pipeline() as pipe:
            await pipe.watch('a', 'b')
            await r.set('b', 3)
            pipe.multi()
            await pipe.get('a')

# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: aredis/exceptions.py
# class WatchError(RedisError):
#     pass
# 
# class ResponseError(RedisError):
#     pass


# Path: tests/client/test_pipeline.py
import pytest
from aredis.utils import b
from aredis.exceptions import (WatchError,
                               ResponseError)

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_watch_succeed(self, r):
        await r.flushdb()
        await r.set('a', 1)
        await r.set('b', 2)

        async with await r.pipeline() as pipe:
            await pipe.watch('a', 'b')
            assert pipe.watching
            a_value = await pipe.get('a')
            b_value = await pipe.get('b')
            assert a_value == b('1')
            assert b_value == b('2')
            pipe.multi()

            await pipe.set('c', 3)
            assert await pipe.execute() == [True]
            assert not pipe.watching

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_watch_failure(self, r):
        await r.flushdb()
        await r.set('a', 1)
        await r.set('b', 2)

        async with await r.pipeline() as pipe:
            await pipe.watch('a', 'b')
            await r.set('b', 3)
            pipe.multi()
            await pipe.get('a')

            with pytest.raises(WatchError):