Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Fix test_invalid_response on older python versions without AsyncMock
Browse files Browse the repository at this point in the history
  • Loading branch information
m-novikov committed Nov 20, 2021
1 parent aba24b4 commit b00926d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/test_connection.py
@@ -1,21 +1,24 @@
import asyncio
from typing import TYPE_CHECKING
from unittest import mock

import pytest

from aioredis.connection import PythonParser, UnixDomainSocketConnection
from aioredis.exceptions import InvalidResponse

from .compat import mock


@pytest.mark.asyncio
@pytest.mark.parametrize("create_redis", [(True, PythonParser)], indirect=True)
async def test_invalid_response(create_redis):
r = await create_redis()

raw = b"x"
readline_mock = mock.AsyncMock(return_value=raw)

parser: "PythonParser" = r.connection._parser
with mock.patch.object(parser._buffer, "readline", return_value=raw):
with mock.patch.object(parser._buffer, "readline", readline_mock):
with pytest.raises(InvalidResponse) as cm:
await parser.read_response()
assert str(cm.value) == "Protocol Error: %r" % raw
Expand Down

0 comments on commit b00926d

Please sign in to comment.