Skip to content

Commit f4aee4c

Browse files
committed
Fix unittest mocking when SocketBuffer is gone
1 parent 5a3f7b1 commit f4aee4c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tests/test_asyncio/test_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
from redis.asyncio.retry import Retry
1414
from redis.backoff import NoBackoff
1515
from redis.exceptions import ConnectionError, InvalidResponse, TimeoutError
16-
from redis.utils import HIREDIS_AVAILABLE
1716
from tests.conftest import skip_if_server_version_lt
1817

1918
from .compat import mock
2019

2120

2221
@pytest.mark.onlynoncluster
23-
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
2422
async def test_invalid_response(create_redis):
2523
r = await create_redis(single_connection_client=True)
2624

2725
raw = b"x"
28-
readline_mock = mock.AsyncMock(return_value=raw)
2926

3027
parser: "PythonParser" = r.connection._parser
31-
with mock.patch.object(parser._buffer, "readline", readline_mock):
28+
if not isinstance(parser, PythonParser):
29+
pytest.skip("PythonParser only")
30+
stream_mock = mock.Mock(parser._stream)
31+
stream_mock.readline.return_value = raw + b"\r\n"
32+
with mock.patch.object(parser, "_stream", stream_mock):
3233
with pytest.raises(InvalidResponse) as cm:
3334
await parser.read_response()
3435
assert str(cm.value) == f"Protocol Error: {raw!r}"

0 commit comments

Comments
 (0)