Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use mock from standard library #11588

Merged
merged 7 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11588.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace `mock` package by its standard library version.
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ def exec_file(path_segments):
# Tests assume that all optional dependencies are installed.
#
# parameterized_class decorator was introduced in parameterized 0.7.0
#
# We use `mock` library as that backports `AsyncMock` to Python 3.6
CONDITIONAL_REQUIREMENTS["test"] = ["parameterized>=0.7.0", "mock>=4.0.0"]
CONDITIONAL_REQUIREMENTS["test"] = ["parameterized>=0.7.0"]

CONDITIONAL_REQUIREMENTS["dev"] = (
CONDITIONAL_REQUIREMENTS["lint"]
Expand Down
17 changes: 8 additions & 9 deletions tests/storage/test_background_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Use backported mock for AsyncMock support on Python 3.6.
from mock import Mock
from unittest.mock import Mock

from twisted.internet.defer import Deferred, ensureDeferred

from synapse.storage.background_updates import BackgroundUpdater

from tests import unittest
from tests.test_utils import make_awaitable
from tests.test_utils import make_awaitable, simple_async_mock


class BackgroundUpdateTestCase(unittest.HomeserverTestCase):
Expand Down Expand Up @@ -116,14 +115,14 @@ def prepare(self, reactor, clock, homeserver):
)

# Mock out the AsyncContextManager
self._update_ctx_manager = Mock(spec=["__aenter__", "__aexit__"])
self._update_ctx_manager.__aenter__ = Mock(
return_value=make_awaitable(None),
)
self._update_ctx_manager.__aexit__ = Mock(return_value=make_awaitable(None))
class MockCM:
__aenter__ = simple_async_mock(return_value=None)
__aexit__ = simple_async_mock(return_value=None)

self._update_ctx_manager = MockCM

# Mock out the `update_handler` callback
self._on_update = Mock(return_value=self._update_ctx_manager)
self._on_update = Mock(return_value=self._update_ctx_manager())

# Define a default batch size value that's not the same as the internal default
# value (100).
Expand Down