Skip to content

Commit 5d790ee

Browse files
committed
Remove unnecessary mock compat code
1 parent 91b2344 commit 5d790ee

11 files changed

+21
-32
lines changed

dev_requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ flake8-isort
55
flake8
66
flynt~=0.69.0
77
invoke==2.2.0
8-
mock
98
packaging>=20.4
109
pytest
1110
pytest-asyncio>=0.23.0,<0.24.0

tests/test_asyncio/compat.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import asyncio
2-
from unittest import mock
3-
4-
try:
5-
mock.AsyncMock
6-
except AttributeError:
7-
from unittest import mock
8-
91
try:
102
from contextlib import aclosing
113
except ImportError:
@@ -17,7 +9,3 @@ async def aclosing(thing):
179
yield thing
1810
finally:
1911
await thing.aclose()
20-
21-
22-
def create_task(coroutine):
23-
return asyncio.create_task(coroutine)

tests/test_asyncio/conftest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from datetime import datetime, timezone
44
from enum import Enum
55
from typing import Union
6+
from unittest import mock
7+
from unittest.mock import Mock
68

79
import pytest
810
import pytest_asyncio
911
import redis.asyncio as redis
10-
from mock.mock import Mock
1112
from packaging.version import Version
1213
from redis.asyncio import Sentinel
1314
from redis.asyncio.client import Monitor
@@ -36,8 +37,6 @@
3637
)
3738
from tests.conftest import REDIS_INFO
3839

39-
from .compat import mock
40-
4140

4241
class AuthType(Enum):
4342
MANAGED_IDENTITY = "managed_identity"

tests/test_asyncio/test_cluster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ssl
55
import warnings
66
from typing import Any, Awaitable, Callable, Dict, List, Optional, Type, Union
7+
from unittest import mock
78
from urllib.parse import urlparse
89

910
import pytest
@@ -38,7 +39,7 @@
3839
)
3940

4041
from ..ssl_utils import get_tls_certificates
41-
from .compat import aclosing, mock
42+
from .compat import aclosing
4243

4344
pytestmark = pytest.mark.onlycluster
4445

tests/test_asyncio/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import socket
33
import types
44
from errno import ECONNREFUSED
5+
from unittest import mock
56
from unittest.mock import patch
67

78
import pytest
@@ -25,7 +26,6 @@
2526
from redis.utils import HIREDIS_AVAILABLE
2627
from tests.conftest import skip_if_server_version_lt
2728

28-
from .compat import mock
2929
from .mocks import MockStream
3030

3131

tests/test_asyncio/test_connection_pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import re
33
from contextlib import asynccontextmanager
4+
from unittest import mock
45

56
import pytest
67
import pytest_asyncio
@@ -9,7 +10,7 @@
910
from redis.auth.token import TokenInterface
1011
from tests.conftest import skip_if_redis_enterprise, skip_if_server_version_lt
1112

12-
from .compat import aclosing, mock
13+
from .compat import aclosing
1314
from .test_pubsub import wait_for_message
1415

1516

tests/test_asyncio/test_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from asyncio import Lock as AsyncLock
55
from asyncio import sleep as async_sleep
66
from typing import Optional, Tuple, Union
7+
from unittest.mock import Mock, call
78

89
import pytest
910
import pytest_asyncio
1011
import redis
11-
from mock.mock import Mock, call
1212
from redis import AuthenticationError, DataError, RedisError, ResponseError
1313
from redis.asyncio import Connection, ConnectionPool, Redis
1414
from redis.asyncio.retry import Retry

tests/test_asyncio/test_pipeline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from unittest import mock
2+
13
import pytest
24
import redis
35
from tests.conftest import skip_if_server_version_lt
46

5-
from .compat import aclosing, mock
7+
from .compat import aclosing
68
from .conftest import wait_for_command
79

810

tests/test_asyncio/test_pubsub.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from redis.utils import HIREDIS_AVAILABLE
2121
from tests.conftest import get_protocol_version, skip_if_server_version_lt
2222

23-
from .compat import aclosing, create_task, mock
23+
from .compat import aclosing
2424

2525

2626
def with_timeout(t):
@@ -733,7 +733,7 @@ async def loop_step():
733733
await messages.put(message)
734734
break
735735

736-
task = asyncio.get_running_loop().create_task(loop())
736+
task = asyncio.create_task(loop())
737737
# get the initial connect message
738738
async with async_timeout(1):
739739
message = await messages.get()
@@ -782,7 +782,7 @@ def callback(message):
782782
messages = asyncio.Queue()
783783
p = pubsub
784784
await self._subscribe(p, foo=callback)
785-
task = asyncio.get_running_loop().create_task(p.run())
785+
task = asyncio.create_task(p.run())
786786
await r.publish("foo", "bar")
787787
message = await messages.get()
788788
task.cancel()
@@ -805,8 +805,8 @@ def exception_handler_callback(e, pubsub) -> None:
805805
exceptions = asyncio.Queue()
806806
p = pubsub
807807
await self._subscribe(p, foo=lambda x: None)
808-
with mock.patch.object(p, "get_message", side_effect=Exception("error")):
809-
task = asyncio.get_running_loop().create_task(
808+
with patch.object(p, "get_message", side_effect=Exception("error")):
809+
task = asyncio.create_task(
810810
p.run(exception_handler=exception_handler_callback)
811811
)
812812
e = await exceptions.get()
@@ -823,7 +823,7 @@ def callback(message):
823823

824824
messages = asyncio.Queue()
825825
p = pubsub
826-
task = asyncio.get_running_loop().create_task(p.run())
826+
task = asyncio.create_task(p.run())
827827
# wait until loop gets settled. Add a subscription
828828
await asyncio.sleep(0.1)
829829
await p.subscribe(foo=callback)
@@ -867,7 +867,7 @@ async def mysetup(self, r, method):
867867
else:
868868
self.get_message = self.loop_step_listen
869869

870-
self.task = create_task(self.loop())
870+
self.task = asyncio.create_task(self.loop())
871871
# get the initial connect message
872872
message = await self.messages.get()
873873
assert message == {
@@ -903,7 +903,7 @@ async def test_reconnect_socket_error(self, r: redis.Redis, method):
903903
async with self.cond:
904904
assert self.state == 0
905905
self.state = 1
906-
with mock.patch.object(self.pubsub.connection, "_parser") as m:
906+
with patch.object(self.pubsub.connection, "_parser") as m:
907907
m.read_response.side_effect = socket.error
908908
m.can_read_destructive.side_effect = socket.error
909909
# wait until task noticies the disconnect until we

tests/test_asyncio/test_sentinel_managed_connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import socket
2+
from unittest import mock
23

34
import pytest
45
from redis.asyncio.retry import Retry
56
from redis.asyncio.sentinel import SentinelManagedConnection
67
from redis.backoff import NoBackoff
78

8-
from .compat import mock
9-
109
pytestmark = pytest.mark.asyncio
1110

1211

0 commit comments

Comments
 (0)