Skip to content

Commit 92b071d

Browse files
authored
refactor: no need to specify mock (#702)
It's now part of the Python stdlib since `3.3`. So no need to specify it.
1 parent bcc9685 commit 92b071d

File tree

9 files changed

+35
-39
lines changed

9 files changed

+35
-39
lines changed

constraints.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
black==22.10.0
33
coverage==6.3.2
44
flake8==5.0.2
5-
mock==3.0.5
65
objgraph==3.5.0
76
pytest==6.2.5
87
pytest-cov==3.0.0

kazoo/tests/test__connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import threading
44
import time
55
import uuid
6+
from unittest.mock import patch
67
import struct
78
import sys
89

910
import pytest
10-
import mock
1111

1212
from kazoo.exceptions import ConnectionLoss
1313
from kazoo.protocol.serialization import (
@@ -160,7 +160,7 @@ def bad_deserialize(_bytes, offset):
160160
# continues to retry. This partially reproduces a rare bug seen
161161
# in production.
162162

163-
with mock.patch.object(Connect, "deserialize") as mock_deserialize:
163+
with patch.object(Connect, "deserialize") as mock_deserialize:
164164
mock_deserialize.side_effect = bad_deserialize
165165
try:
166166
handler.select = delayed_select

kazoo/tests/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import importlib
33
import uuid
44

5-
from mock import patch, call, Mock
5+
from unittest.mock import patch, call, Mock
66
import pytest
77
from objgraph import count as count_refs_by_type
88

kazoo/tests/test_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import time
55
import uuid
66
import unittest
7+
from unittest.mock import Mock, MagicMock, patch
78

8-
import mock
9-
from mock import patch
109
import pytest
1110

1211
from kazoo.testing import KazooTestCase
@@ -479,7 +478,7 @@ def test_server_version_retries_fail(self):
479478
"zookeeper.version=1.",
480479
"zookeeper.ver",
481480
]
482-
client.command = mock.MagicMock()
481+
client.command = MagicMock()
483482
client.command.side_effect = side_effects
484483
with pytest.raises(KazooException):
485484
client.server_version(retries=len(side_effects) - 1)
@@ -490,7 +489,7 @@ def test_server_version_retries_eventually_ok(self):
490489
side_effects = []
491490
for i in range(0, len(actual_version) + 1):
492491
side_effects.append(actual_version[0:i])
493-
client.command = mock.MagicMock()
492+
client.command = MagicMock()
494493
client.command.side_effect = side_effects
495494
assert client.server_version(retries=len(side_effects) - 1) == (1, 2)
496495

@@ -1343,7 +1342,7 @@ def test_session_callback_states(self):
13431342
class TestCallbacks(KazooTestCase):
13441343
def test_async_result_callbacks_are_always_called(self):
13451344
# create a callback object
1346-
callback_mock = mock.Mock()
1345+
callback_mock = Mock()
13471346

13481347
# simulate waiting for a response
13491348
async_result = self.client.handler.async_result()

kazoo/tests/test_lock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import collections
2-
import mock
32
import threading
43
import unittest
4+
from unittest.mock import MagicMock
55
import uuid
66

77
import pytest
@@ -803,7 +803,7 @@ def test_get_predecessor(self):
803803
goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031"
804804
pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032"
805805
children = ["hello", goLock, "world", pyLock]
806-
client = mock.MagicMock()
806+
client = MagicMock()
807807
client.get_children.return_value = children
808808
lock = Lock(client, "test")
809809
assert lock._get_predecessor(pyLock) is None
@@ -815,7 +815,7 @@ def test_get_predecessor_go(self):
815815
goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031"
816816
pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032"
817817
children = ["hello", goLock, "world", pyLock]
818-
client = mock.MagicMock()
818+
client = MagicMock()
819819
client.get_children.return_value = children
820820
lock = Lock(client, "test", extra_lock_patterns=["-lock-"])
821821
assert lock._get_predecessor(pyLock) == goLock

kazoo/tests/test_partitioner.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import uuid
22
import threading
33
import time
4-
5-
import mock
4+
from unittest.mock import patch
65

76
from kazoo.exceptions import LockTimeout
87
from kazoo.testing import KazooTestCase
@@ -154,7 +153,7 @@ def get_lock(path):
154153
lock = locks.setdefault(path, self.client.handler.lock_object())
155154
return SlowLockMock(self.client, lock)
156155

157-
with mock.patch.object(self.client, "Lock", side_effect=get_lock):
156+
with patch.object(self.client, "Lock", side_effect=get_lock):
158157
# Create first partitioner. It will start to acquire the set
159158
# members.
160159
self.__create_partitioner(identifier="0", size=2)
@@ -192,7 +191,7 @@ def get_lock(path):
192191

193192
return SlowLockMock(self.client, lock, delay_time=delay_time)
194193

195-
with mock.patch.object(self.client, "Lock", side_effect=get_lock):
194+
with patch.object(self.client, "Lock", side_effect=get_lock):
196195
# Create first partitioner. It will start to acquire the set
197196
# members.
198197
self.__create_partitioner(identifier="0", size=2)

kazoo/tests/test_threading_handler.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import threading
22
import unittest
3+
from unittest.mock import Mock
34

4-
import mock
55
import pytest
66

77

@@ -79,7 +79,7 @@ def _makeHandler(self):
7979
return SequentialThreadingHandler()
8080

8181
def test_ready(self):
82-
mock_handler = mock.Mock()
82+
mock_handler = Mock()
8383
async_result = self._makeOne(mock_handler)
8484

8585
assert async_result.ready() is False
@@ -89,8 +89,8 @@ def test_ready(self):
8989
assert async_result.exception is None
9090

9191
def test_callback_queued(self):
92-
mock_handler = mock.Mock()
93-
mock_handler.completion_queue = mock.Mock()
92+
mock_handler = Mock()
93+
mock_handler.completion_queue = Mock()
9494
async_result = self._makeOne(mock_handler)
9595

9696
async_result.rawlink(lambda a: a)
@@ -99,8 +99,8 @@ def test_callback_queued(self):
9999
assert mock_handler.completion_queue.put.called
100100

101101
def test_set_exception(self):
102-
mock_handler = mock.Mock()
103-
mock_handler.completion_queue = mock.Mock()
102+
mock_handler = Mock()
103+
mock_handler.completion_queue = Mock()
104104
async_result = self._makeOne(mock_handler)
105105
async_result.rawlink(lambda a: a)
106106
async_result.set_exception(ImportError("Error occured"))
@@ -109,7 +109,7 @@ def test_set_exception(self):
109109
assert mock_handler.completion_queue.put.called
110110

111111
def test_get_wait_while_setting(self):
112-
mock_handler = mock.Mock()
112+
mock_handler = Mock()
113113
async_result = self._makeOne(mock_handler)
114114

115115
lst = []
@@ -132,7 +132,7 @@ def wait_for_val():
132132
th.join()
133133

134134
def test_get_with_nowait(self):
135-
mock_handler = mock.Mock()
135+
mock_handler = Mock()
136136
async_result = self._makeOne(mock_handler)
137137
timeout = self._makeHandler().timeout_exception
138138

@@ -143,7 +143,7 @@ def test_get_with_nowait(self):
143143
async_result.get_nowait()
144144

145145
def test_get_with_exception(self):
146-
mock_handler = mock.Mock()
146+
mock_handler = Mock()
147147
async_result = self._makeOne(mock_handler)
148148

149149
lst = []
@@ -170,7 +170,7 @@ def wait_for_val():
170170
th.join()
171171

172172
def test_wait(self):
173-
mock_handler = mock.Mock()
173+
mock_handler = Mock()
174174
async_result = self._makeOne(mock_handler)
175175

176176
lst = []
@@ -202,7 +202,7 @@ def test_wait_race(self):
202202
Guards against the reappearance of:
203203
https://github.com/python-zk/kazoo/issues/485
204204
"""
205-
mock_handler = mock.Mock()
205+
mock_handler = Mock()
206206
async_result = self._makeOne(mock_handler)
207207

208208
async_result.set("immediate")
@@ -225,7 +225,7 @@ def wait_for_val():
225225
th.join()
226226

227227
def test_set_before_wait(self):
228-
mock_handler = mock.Mock()
228+
mock_handler = Mock()
229229
async_result = self._makeOne(mock_handler)
230230

231231
lst = []
@@ -244,7 +244,7 @@ def wait_for_val():
244244
th.join()
245245

246246
def test_set_exc_before_wait(self):
247-
mock_handler = mock.Mock()
247+
mock_handler = Mock()
248248
async_result = self._makeOne(mock_handler)
249249

250250
lst = []
@@ -267,7 +267,7 @@ def wait_for_val():
267267
th.join()
268268

269269
def test_linkage(self):
270-
mock_handler = mock.Mock()
270+
mock_handler = Mock()
271271
async_result = self._makeOne(mock_handler)
272272
cv = threading.Event()
273273

@@ -292,7 +292,7 @@ def wait_for_val():
292292
th.join()
293293

294294
def test_linkage_not_ready(self):
295-
mock_handler = mock.Mock()
295+
mock_handler = Mock()
296296
async_result = self._makeOne(mock_handler)
297297

298298
lst = []
@@ -306,7 +306,7 @@ def add_on():
306306
assert mock_handler.completion_queue.put.called
307307

308308
def test_link_and_unlink(self):
309-
mock_handler = mock.Mock()
309+
mock_handler = Mock()
310310
async_result = self._makeOne(mock_handler)
311311

312312
lst = []
@@ -323,7 +323,7 @@ def add_on():
323323
def test_captured_exception(self):
324324
from kazoo.handlers.utils import capture_exceptions
325325

326-
mock_handler = mock.Mock()
326+
mock_handler = Mock()
327327
async_result = self._makeOne(mock_handler)
328328

329329
@capture_exceptions(async_result)
@@ -338,7 +338,7 @@ def exceptional_function():
338338
def test_no_capture_exceptions(self):
339339
from kazoo.handlers.utils import capture_exceptions
340340

341-
mock_handler = mock.Mock()
341+
mock_handler = Mock()
342342
async_result = self._makeOne(mock_handler)
343343

344344
lst = []
@@ -359,7 +359,7 @@ def regular_function():
359359
def test_wraps(self):
360360
from kazoo.handlers.utils import wrap
361361

362-
mock_handler = mock.Mock()
362+
mock_handler = Mock()
363363
async_result = self._makeOne(mock_handler)
364364

365365
lst = []
@@ -378,8 +378,8 @@ def regular_function():
378378
assert async_result.get() == "hello"
379379

380380
def test_multiple_callbacks(self):
381-
mockback1 = mock.Mock(name="mockback1")
382-
mockback2 = mock.Mock(name="mockback2")
381+
mockback1 = Mock(name="mockback1")
382+
mockback2 = Mock(name="mockback2")
383383
handler = self._makeHandler()
384384
handler.start()
385385

kazoo/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
2+
from unittest.mock import patch
23

3-
from mock import patch
44
import pytest
55

66
try:

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dev =
5454
flake8
5555

5656
test =
57-
mock
5857
objgraph
5958
pytest
6059
pytest-cov

0 commit comments

Comments
 (0)