Skip to content

Commit

Permalink
refactor: no need to specify mock
Browse files Browse the repository at this point in the history
It's now part of the Python stdlib since `3.3`.

So no need to specify it.
  • Loading branch information
jeffwidman committed Feb 5, 2023
1 parent bcc9685 commit 064fed0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 39 deletions.
1 change: 0 additions & 1 deletion constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
black==22.10.0
coverage==6.3.2
flake8==5.0.2
mock==3.0.5
objgraph==3.5.0
pytest==6.2.5
pytest-cov==3.0.0
Expand Down
4 changes: 2 additions & 2 deletions kazoo/tests/test__connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import threading
import time
import uuid
from unittest.mock import patch
import struct
import sys

import pytest
import mock

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

with mock.patch.object(Connect, "deserialize") as mock_deserialize:
with patch.object(Connect, "deserialize") as mock_deserialize:
mock_deserialize.side_effect = bad_deserialize
try:
handler.select = delayed_select
Expand Down
2 changes: 1 addition & 1 deletion kazoo/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import importlib
import uuid

from mock import patch, call, Mock
from unittest.mock import patch, call, Mock
import pytest
from objgraph import count as count_refs_by_type

Expand Down
9 changes: 4 additions & 5 deletions kazoo/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import time
import uuid
import unittest
from unittest.mock import Mock, MagicMock, patch

import mock
from mock import patch
import pytest

from kazoo.testing import KazooTestCase
Expand Down Expand Up @@ -479,7 +478,7 @@ def test_server_version_retries_fail(self):
"zookeeper.version=1.",
"zookeeper.ver",
]
client.command = mock.MagicMock()
client.command = MagicMock()
client.command.side_effect = side_effects
with pytest.raises(KazooException):
client.server_version(retries=len(side_effects) - 1)
Expand All @@ -490,7 +489,7 @@ def test_server_version_retries_eventually_ok(self):
side_effects = []
for i in range(0, len(actual_version) + 1):
side_effects.append(actual_version[0:i])
client.command = mock.MagicMock()
client.command = MagicMock()
client.command.side_effect = side_effects
assert client.server_version(retries=len(side_effects) - 1) == (1, 2)

Expand Down Expand Up @@ -1343,7 +1342,7 @@ def test_session_callback_states(self):
class TestCallbacks(KazooTestCase):
def test_async_result_callbacks_are_always_called(self):
# create a callback object
callback_mock = mock.Mock()
callback_mock = Mock()

# simulate waiting for a response
async_result = self.client.handler.async_result()
Expand Down
6 changes: 3 additions & 3 deletions kazoo/tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import collections
import mock
import threading
import unittest
from unittest.mock import MagicMock
import uuid

import pytest
Expand Down Expand Up @@ -803,7 +803,7 @@ def test_get_predecessor(self):
goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031"
pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032"
children = ["hello", goLock, "world", pyLock]
client = mock.MagicMock()
client = MagicMock()
client.get_children.return_value = children
lock = Lock(client, "test")
assert lock._get_predecessor(pyLock) is None
Expand All @@ -815,7 +815,7 @@ def test_get_predecessor_go(self):
goLock = "_c_8eb60557ba51e0da67eefc47467d3f34-lock-0000000031"
pyLock = "514e5a831836450cb1a56c741e990fd8__lock__0000000032"
children = ["hello", goLock, "world", pyLock]
client = mock.MagicMock()
client = MagicMock()
client.get_children.return_value = children
lock = Lock(client, "test", extra_lock_patterns=["-lock-"])
assert lock._get_predecessor(pyLock) == goLock
7 changes: 3 additions & 4 deletions kazoo/tests/test_partitioner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import uuid
import threading
import time

import mock
from unittest.mock import patch

from kazoo.exceptions import LockTimeout
from kazoo.testing import KazooTestCase
Expand Down Expand Up @@ -154,7 +153,7 @@ def get_lock(path):
lock = locks.setdefault(path, self.client.handler.lock_object())
return SlowLockMock(self.client, lock)

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

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

with mock.patch.object(self.client, "Lock", side_effect=get_lock):
with patch.object(self.client, "Lock", side_effect=get_lock):
# Create first partitioner. It will start to acquire the set
# members.
self.__create_partitioner(identifier="0", size=2)
Expand Down
42 changes: 21 additions & 21 deletions kazoo/tests/test_threading_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import threading
import unittest
from unittest.mock import Mock

import mock
import pytest


Expand Down Expand Up @@ -79,7 +79,7 @@ def _makeHandler(self):
return SequentialThreadingHandler()

def test_ready(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

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

def test_callback_queued(self):
mock_handler = mock.Mock()
mock_handler.completion_queue = mock.Mock()
mock_handler = Mock()
mock_handler.completion_queue = Mock()
async_result = self._makeOne(mock_handler)

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

def test_set_exception(self):
mock_handler = mock.Mock()
mock_handler.completion_queue = mock.Mock()
mock_handler = Mock()
mock_handler.completion_queue = Mock()
async_result = self._makeOne(mock_handler)
async_result.rawlink(lambda a: a)
async_result.set_exception(ImportError("Error occured"))
Expand All @@ -109,7 +109,7 @@ def test_set_exception(self):
assert mock_handler.completion_queue.put.called

def test_get_wait_while_setting(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

lst = []
Expand All @@ -132,7 +132,7 @@ def wait_for_val():
th.join()

def test_get_with_nowait(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)
timeout = self._makeHandler().timeout_exception

Expand All @@ -143,7 +143,7 @@ def test_get_with_nowait(self):
async_result.get_nowait()

def test_get_with_exception(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

lst = []
Expand All @@ -170,7 +170,7 @@ def wait_for_val():
th.join()

def test_wait(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

lst = []
Expand Down Expand Up @@ -202,7 +202,7 @@ def test_wait_race(self):
Guards against the reappearance of:
https://github.com/python-zk/kazoo/issues/485
"""
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

async_result.set("immediate")
Expand All @@ -225,7 +225,7 @@ def wait_for_val():
th.join()

def test_set_before_wait(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

lst = []
Expand All @@ -244,7 +244,7 @@ def wait_for_val():
th.join()

def test_set_exc_before_wait(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

lst = []
Expand All @@ -267,7 +267,7 @@ def wait_for_val():
th.join()

def test_linkage(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)
cv = threading.Event()

Expand All @@ -292,7 +292,7 @@ def wait_for_val():
th.join()

def test_linkage_not_ready(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

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

def test_link_and_unlink(self):
mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

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

mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

@capture_exceptions(async_result)
Expand All @@ -338,7 +338,7 @@ def exceptional_function():
def test_no_capture_exceptions(self):
from kazoo.handlers.utils import capture_exceptions

mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

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

mock_handler = mock.Mock()
mock_handler = Mock()
async_result = self._makeOne(mock_handler)

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

def test_multiple_callbacks(self):
mockback1 = mock.Mock(name="mockback1")
mockback2 = mock.Mock(name="mockback2")
mockback1 = Mock(name="mockback1")
mockback2 = Mock(name="mockback2")
handler = self._makeHandler()
handler.start()

Expand Down
2 changes: 1 addition & 1 deletion kazoo/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from unittest.mock import patch

from mock import patch
import pytest

try:
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ dev =
flake8

test =
mock
objgraph
pytest
pytest-cov
Expand Down

0 comments on commit 064fed0

Please sign in to comment.