Use mock from the stdlib. (#9772)

This commit is contained in:
Patrick Cloke 2021-04-09 13:44:38 -04:00 committed by GitHub
parent f946450184
commit 0b3112123d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
82 changed files with 86 additions and 126 deletions

1
changelog.d/9772.misc Normal file
View File

@ -0,0 +1 @@
Use mock from the standard library instead of a separate package.

View File

@ -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

View File

@ -110,7 +110,7 @@ CONDITIONAL_REQUIREMENTS["mypy"] = ["mypy==0.812", "mypy-zope==0.2.13"]
# 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",

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
@ -314,7 +313,8 @@ class PresenceRouterTestCase(FederatingHomeserverTestCase):
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"]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -14,7 +14,7 @@
# limitations under the License.
from mock import Mock
from unittest.mock import Mock
import synapse
import synapse.api.errors

View File

@ -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

View File

@ -16,8 +16,7 @@
# limitations under the License.
import copy
import mock
from unittest import mock
from synapse.api.errors import SynapseError

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -13,8 +13,7 @@
# limitations under the License.
from typing import Optional
from mock import Mock
from unittest.mock import Mock
import attr

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 (

View File

@ -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

View File

@ -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

View File

@ -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
@ -358,7 +358,8 @@ class ModuleApiTestCase(FederatingHomeserverTestCase):
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"]

View File

@ -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

View File

@ -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

View File

@ -15,7 +15,7 @@
# type: ignore
from mock import Mock
from unittest.mock import Mock
from synapse.replication.tcp.streams._base import ReceiptsStream

View File

@ -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

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from synapse.app.generic_worker import GenericWorkerServer
from synapse.replication.tcp.commands import FederationAckCommand

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from mock import Mock
from unittest.mock import Mock
from synapse.api.constants import EventTypes, Membership
from synapse.events.builder import EventBuilderFactory

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from mock import Mock
from unittest.mock import Mock
from twisted.internet import defer

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
from mock import patch
from unittest.mock import patch
from synapse.api.room_versions import RoomVersion
from synapse.rest import admin

View File

@ -17,8 +17,7 @@ import json
import os
import urllib.parse
from binascii import unhexlify
from mock import Mock
from unittest.mock import Mock
from twisted.internet.defer import Deferred

View File

@ -16,8 +16,7 @@
import json
import urllib.parse
from typing import List, Optional
from mock import Mock
from unittest.mock import Mock
import synapse.rest.admin
from synapse.api.constants import EventTypes, Membership

View File

@ -19,8 +19,7 @@ import json
import urllib.parse
from binascii import unhexlify
from typing import List, Optional
from mock import Mock
from unittest.mock import Mock
import synapse.rest.admin
from synapse.api.constants import UserTypes

View File

@ -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 EventTypes
from synapse.rest import admin

View File

@ -12,7 +12,7 @@
# 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
import synapse.rest.admin
from synapse.api.constants import EventTypes

View File

@ -14,8 +14,7 @@
# limitations under the License.
import threading
from typing import Dict
from mock import Mock
from unittest.mock import Mock
from synapse.events import EventBase
from synapse.module_api import ModuleApi

View File

@ -1,4 +1,4 @@
from mock import Mock, call
from unittest.mock import Mock, call
from twisted.internet import defer, reactor

View File

@ -15,7 +15,7 @@
""" Tests REST events for /events paths."""
from mock import Mock
from unittest.mock import Mock
import synapse.rest.admin
from synapse.rest.client.v1 import events, login, room

View File

@ -16,10 +16,9 @@
import time
import urllib.parse
from typing import Any, Dict, List, Optional, Union
from unittest.mock import Mock
from urllib.parse import urlencode
from mock import Mock
import pymacaroons
from twisted.web.resource import Resource

View File

@ -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

View File

@ -20,10 +20,9 @@
import json
from typing import Iterable
from unittest.mock import Mock
from urllib import parse as urlparse
from mock import Mock
import synapse.rest.admin
from synapse.api.constants import EventContentFields, EventTypes, Membership
from synapse.handlers.pagination import PurgeStatus

View File

@ -16,7 +16,7 @@
"""Tests REST events for /rooms paths."""
from mock import Mock
from unittest.mock import Mock
from synapse.rest.client.v1 import room
from synapse.types import UserID

View File

@ -21,8 +21,7 @@ import re
import time
import urllib.parse
from typing import Any, Dict, Mapping, MutableMapping, Optional
from mock import patch
from unittest.mock import patch
import attr

View File

@ -14,8 +14,7 @@
# limitations under the License.
import urllib.parse
from io import BytesIO, StringIO
from mock import Mock
from unittest.mock import Mock
import signedjson.key
from canonicaljson import encode_canonical_json

View File

@ -18,10 +18,9 @@ import tempfile
from binascii import unhexlify
from io import BytesIO
from typing import Optional
from unittest.mock import Mock
from urllib import parse
from mock import Mock
import attr
from parameterized import parameterized_class
from PIL import Image as Image

View File

@ -15,8 +15,7 @@
import json
import os
import re
from mock import patch
from unittest.mock import patch
from twisted.internet._resolver import HostResolution
from twisted.internet.address import IPv4Address, IPv6Address

View File

@ -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._scripts.register_new_matrix_user import request_registration

View File

@ -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

View File

@ -15,8 +15,7 @@
import json
import os
import tempfile
from mock import Mock
from unittest.mock import Mock
import yaml

View File

@ -1,4 +1,4 @@
from mock import Mock
from unittest.mock import Mock
from synapse.storage.background_updates import BackgroundUpdater

View File

@ -15,8 +15,7 @@
from collections import OrderedDict
from mock import Mock
from unittest.mock import Mock
from twisted.internet import defer

View File

@ -14,9 +14,7 @@
# limitations under the License.
import os.path
from unittest.mock import patch
from mock import Mock
from unittest.mock import Mock, patch
import synapse.rest.admin
from synapse.api.constants import EventTypes

View File

@ -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
import synapse.rest.admin
from synapse.http.site import XForwardedForRequest

View File

@ -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.unittest import HomeserverTestCase

View File

@ -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

View File

@ -14,7 +14,7 @@
# 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 synapse.util.distributor import Distributor

View File

@ -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.defer import succeed

View File

@ -14,8 +14,7 @@
# limitations under the License.
import resource
import mock
from unittest import mock
from synapse.app.phone_stats_home import phone_stats_home

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List, Optional
from mock import Mock
from unittest.mock import Mock
from twisted.internet import defer

View File

@ -13,8 +13,7 @@
# limitations under the License.
import json
from mock import Mock
from unittest.mock import Mock
from twisted.test.proto_helpers import MemoryReactorClock

View File

@ -21,8 +21,7 @@ import sys
import warnings
from asyncio import Future
from typing import Any, Awaitable, Callable, TypeVar
from mock import Mock
from unittest.mock import Mock
import attr

View File

@ -14,8 +14,7 @@
# limitations under the License.
import logging
from typing import Optional
from mock import Mock
from unittest.mock import Mock
from twisted.internet import defer
from twisted.internet.defer import succeed

View File

@ -21,8 +21,7 @@ import inspect
import logging
import time
from typing import Callable, Dict, Iterable, Optional, Tuple, Type, TypeVar, Union
from mock import Mock, patch
from unittest.mock import Mock, patch
from canonicaljson import json

View File

@ -15,8 +15,7 @@
# limitations under the License.
import logging
from typing import Set
import mock
from unittest import mock
from twisted.internet import defer, reactor

View File

@ -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.util.caches.ttlcache import TTLCache

View File

@ -16,8 +16,7 @@
import threading
from io import StringIO
from mock import NonCallableMock
from unittest.mock import NonCallableMock
from twisted.internet import defer, reactor

View File

@ -14,7 +14,7 @@
# limitations under the License.
from mock import Mock
from unittest.mock import Mock
from synapse.util.caches.lrucache import LruCache
from synapse.util.caches.treecache import TreeCache

View File

@ -21,10 +21,9 @@ import time
import uuid
import warnings
from typing import Type
from unittest.mock import Mock, patch
from urllib import parse as urlparse
from mock import Mock, patch
from twisted.internet import defer
from synapse.api.constants import EventTypes