summaryrefslogtreecommitdiff
path: root/tests/test_connection.py
blob: 128bac7d96aed7cb66ac69119f6c644f369f387b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from unittest import mock
import pytest

from redis.exceptions import InvalidResponse
from redis.utils import HIREDIS_AVAILABLE


@pytest.mark.skipif(HIREDIS_AVAILABLE, reason='PythonParser only')
def test_invalid_response(r):
    raw = b'x'
    parser = r.connection._parser
    with mock.patch.object(parser._buffer, 'readline', return_value=raw):
        with pytest.raises(InvalidResponse) as cm:
            parser.read_response()
    assert str(cm.value) == 'Protocol Error: %r' % raw