# Path: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")


import pytest
import aredis
from aredis.exceptions import RedisError, ResponseError
from tests.client.conftest import skip_if_server_version_lt




class TestStreams:

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_with_wrong_id(self, r):
        with pytest.raises(RedisError):
            await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id=0,
                         max_len=10, approximate=False)

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_without_given_id(self, r):
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1})
        assert len(stream_id.decode().split('-')) == 2

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_with_given_id(self, r):
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id='12321')
        assert stream_id == b'12321-0'
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id='12321-0')
        assert stream_id == b'12321-0'


# Path: aredis/exceptions.py
# class RedisError(Exception):
#     pass
# 
# class ResponseError(RedisError):
#     pass
# 
# Path: tests/client/conftest.py
# def skip_if_server_version_lt(min_version):
#     loop = asyncio.get_event_loop()
#     version = StrictVersion(loop.run_until_complete(get_version()))
#     check = version < StrictVersion(min_version)
#     return pytest.mark.skipif(check, reason="")


# Path: tests/client/test_streams.py
import pytest
import aredis
from aredis.exceptions import RedisError, ResponseError
from tests.client.conftest import skip_if_server_version_lt





class TestStreams:

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_with_wrong_id(self, r):
        with pytest.raises(RedisError):
            await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id=0,
                         max_len=10, approximate=False)

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_without_given_id(self, r):
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1})
        assert len(stream_id.decode().split('-')) == 2

    @skip_if_server_version_lt('4.9.103')
    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_xadd_with_given_id(self, r):
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id='12321')
        assert stream_id == b'12321-0'
        await r.flushdb()
        stream_id = await r.xadd('test_stream', {'k1': 'v1', 'k2': 1}, stream_id='12321-0')
        assert stream_id == b'12321-0'


    @skip_if_server_version_lt('4.9.103')