Skip to content

Commit

Permalink
Use mock from the stdlib. (matrix-org#9772)
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep authored Apr 9, 2021
1 parent f946450 commit 0b31121
Show file tree
Hide file tree
Showing 82 changed files with 86 additions and 126 deletions.
1 change: 1 addition & 0 deletions changelog.d/9772.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use mock from the standard library instead of a separate package.
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ ignore=W503,W504,E203,E731,E501,B007

[isort]
line_length = 88
sections=FUTURE,STDLIB,COMPAT,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
sections=FUTURE,STDLIB,THIRDPARTY,TWISTED,FIRSTPARTY,TESTS,LOCALFOLDER
default_section=THIRDPARTY
known_first_party = synapse
known_tests=tests
known_compat = mock
known_twisted=twisted,OpenSSL
multi_line_output=3
include_trailing_comma=true
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def exec_file(path_segments):
# Tests assume that all optional dependencies are installed.
#
# parameterized_class decorator was introduced in parameterized 0.7.0
CONDITIONAL_REQUIREMENTS["test"] = ["mock>=2.0", "parameterized>=0.7.0"]
CONDITIONAL_REQUIREMENTS["test"] = ["parameterized>=0.7.0"]

setup(
name="matrix-synapse",
Expand Down
3 changes: 1 addition & 2 deletions synmark/suites/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import logging
import warnings
from io import StringIO

from mock import Mock
from unittest.mock import Mock

from pyperf import perf_counter

Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

import pymacaroons

Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_openid_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock, patch
from unittest.mock import Mock, patch

from parameterized import parameterized

Expand Down
3 changes: 1 addition & 2 deletions tests/appservice/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re

from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer

Expand Down
2 changes: 1 addition & 1 deletion tests/appservice/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer

Expand Down
3 changes: 1 addition & 2 deletions tests/crypto/test_keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time

from mock import Mock
from unittest.mock import Mock

import attr
import canonicaljson
Expand Down
6 changes: 3 additions & 3 deletions tests/events/test_presence_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Dict, Iterable, List, Optional, Set, Tuple, Union

from mock import Mock
from unittest.mock import Mock

import attr

Expand Down Expand Up @@ -314,7 +313,8 @@ def test_send_local_online_presence_to_with_module(self):
self.hs.get_federation_transport_client().send_transaction.call_args_list
)
for call in calls:
federation_transaction = call.args[0] # type: Transaction
call_args = call[0]
federation_transaction = call_args[0] # type: Transaction

# Get the sent EDUs in this transaction
edus = federation_transaction.get_dict()["edus"]
Expand Down
2 changes: 1 addition & 1 deletion tests/federation/test_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from synapse.api.errors import Codes, SynapseError
from synapse.rest import admin
Expand Down
3 changes: 1 addition & 2 deletions tests/federation/test_federation_catch_up.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List, Tuple

from mock import Mock
from unittest.mock import Mock

from synapse.api.constants import EventTypes
from synapse.events import EventBase
Expand Down
3 changes: 1 addition & 2 deletions tests/federation/test_federation_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional

from mock import Mock
from unittest.mock import Mock

from signedjson import key, sign
from signedjson.types import BaseKey, SigningKey
Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.

from collections import Counter

from mock import Mock
from unittest.mock import Mock

import synapse.api.errors
import synapse.handlers.admin
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

import pymacaroons

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_cas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from synapse.handlers.cas_handler import CasResponse

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.


from mock import Mock
from unittest.mock import Mock

import synapse
import synapse.api.errors
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock

from signedjson import key as key, sign as sign

Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_e2e_room_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
# limitations under the License.

import copy

import mock
from unittest import mock

from synapse.api.errors import SynapseError

Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
# limitations under the License.
import json
import os
from unittest.mock import ANY, Mock, patch
from urllib.parse import parse_qs, urlparse

from mock import ANY, Mock, patch

import pymacaroons

from synapse.handlers.sso import MappingException
Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_password_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"""Tests for the password_auth_provider interface"""

from typing import Any, Type, Union

from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.


from mock import Mock, call
from unittest.mock import Mock, call

from signedjson.key import generate_signing_key

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

import synapse.types
from synapse.api.errors import AuthError, SynapseError
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from synapse.api.auth import Auth
from synapse.api.constants import UserTypes
Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

from typing import Optional

from mock import Mock
from unittest.mock import Mock

import attr

Expand Down
3 changes: 1 addition & 2 deletions tests/handlers/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import json
from typing import Dict

from mock import ANY, Mock, call
from unittest.mock import ANY, Mock, call

from twisted.internet import defer
from twisted.web.resource import Resource
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer

Expand Down
3 changes: 1 addition & 2 deletions tests/http/federation/test_matrix_federation_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.
import logging
from typing import Optional

from mock import Mock
from unittest.mock import Mock

import treq
from netaddr import IPSet
Expand Down
2 changes: 1 addition & 1 deletion tests/http/federation/test_srv_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from twisted.internet import defer
from twisted.internet.defer import Deferred
Expand Down
3 changes: 1 addition & 2 deletions tests/http/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

from io import BytesIO

from mock import Mock
from unittest.mock import Mock

from netaddr import IPSet

Expand Down
2 changes: 1 addition & 1 deletion tests/http/test_fedclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from netaddr import IPSet
from parameterized import parameterized
Expand Down
3 changes: 1 addition & 2 deletions tests/http/test_servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.
import json
from io import BytesIO

from mock import Mock
from unittest.mock import Mock

from synapse.api.errors import SynapseError
from synapse.http.servlet import (
Expand Down
2 changes: 1 addition & 1 deletion tests/http/test_simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from netaddr import IPSet

Expand Down
3 changes: 1 addition & 2 deletions tests/logging/test_terse_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import json
import logging
from io import BytesIO, StringIO

from mock import Mock, patch
from unittest.mock import Mock, patch

from twisted.web.server import Request

Expand Down
5 changes: 3 additions & 2 deletions tests/module_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from synapse.api.constants import EduTypes
from synapse.events import EventBase
Expand Down Expand Up @@ -358,7 +358,8 @@ def test_send_local_online_presence_to_federation(self):
self.hs.get_federation_transport_client().send_transaction.call_args_list
)
for call in calls:
federation_transaction = call.args[0] # type: Transaction
call_args = call[0]
federation_transaction = call_args[0] # type: Transaction

# Get the sent EDUs in this transaction
edus = federation_transaction.get_dict()["edus"]
Expand Down
2 changes: 1 addition & 1 deletion tests/push/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from twisted.internet.defer import Deferred

Expand Down
2 changes: 1 addition & 1 deletion tests/replication/slave/storage/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mock import Mock
from unittest.mock import Mock

from tests.replication._base import BaseStreamTestCase

Expand Down
2 changes: 1 addition & 1 deletion tests/replication/tcp/streams/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# type: ignore

from mock import Mock
from unittest.mock import Mock

from synapse.replication.tcp.streams._base import ReceiptsStream

Expand Down
2 changes: 1 addition & 1 deletion tests/replication/tcp/streams/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from mock import Mock
from unittest.mock import Mock

from synapse.handlers.typing import RoomMember
from synapse.replication.tcp.streams import TypingStream
Expand Down
Loading

0 comments on commit 0b31121

Please sign in to comment.