# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# 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 asyncio
import pickle
import time
import pytest
import aredis
from aredis.exceptions import ConnectionError
from aredis.utils import b
from .conftest import skip_if_server_version_lt
#         p.psubscribe(**{self.pattern: self.message_handler})
#         r.publish(self.channel, self.data)
#         assert wait_for_message(p) is None
#         assert self.message == self.make_message('pmessage', self.channel,
#                                                  self.data,
#                                                  pattern=self.pattern)
#
#         # test that we reconnected to the correct pattern
#         p.connection.disconnect()
#         assert wait_for_message(p) is None  # should reconnect
#         new_data = self.data + 'new data'
#         r.publish(self.channel, new_data)
#         assert wait_for_message(p) is None
#         assert self.message == self.make_message('pmessage', self.channel,
#                                                  new_data,
#                                                  pattern=self.pattern)
#
#
class TestPubSubRedisDown:

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_channel_subscribe(self, r):
        r = aredis.StrictRedis(host='localhost', port=6390)
        p = r.pubsub()
        with pytest.raises(ConnectionError):
            await p.subscribe('foo')


class TestPubSubPubSubSubcommands:


# Path: aredis/exceptions.py
# class ConnectionError(RedisError):
#     pass
# 
# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# 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_pubsub.py
import asyncio
import pickle
import time
import pytest
import aredis
from aredis.exceptions import ConnectionError
from aredis.utils import b
from .conftest import skip_if_server_version_lt

#         p.psubscribe(**{self.pattern: self.message_handler})
#         r.publish(self.channel, self.data)
#         assert wait_for_message(p) is None
#         assert self.message == self.make_message('pmessage', self.channel,
#                                                  self.data,
#                                                  pattern=self.pattern)
#
#         # test that we reconnected to the correct pattern
#         p.connection.disconnect()
#         assert wait_for_message(p) is None  # should reconnect
#         new_data = self.data + 'new data'
#         r.publish(self.channel, new_data)
#         assert wait_for_message(p) is None
#         assert self.message == self.make_message('pmessage', self.channel,
#                                                  new_data,
#                                                  pattern=self.pattern)
#
#
class TestPubSubRedisDown:

    @pytest.mark.asyncio(forbid_global_loop=True)
    async def test_channel_subscribe(self, r):
        r = aredis.StrictRedis(host='localhost', port=6390)
        p = r.pubsub()
        with pytest.raises(ConnectionError):
            await p.subscribe('foo')


class TestPubSubPubSubSubcommands:


    @skip_if_server_version_lt('2.8.0')