Skip to content

Commit

Permalink
Use standard library mock when possible
Browse files Browse the repository at this point in the history
Mock has been in the standard library since 3.3.  Use it when available,
falling back to the mock from PyPI if necessary.
  • Loading branch information
carlwgeorge committed Feb 14, 2023
1 parent ac5e46d commit 4776d58
Show file tree
Hide file tree
Showing 32 changed files with 125 additions and 40 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Unit test dependencies
mock
mock; python_version<'3.3'
mypy-extensions; python_version>='3.5'
mypy; python_version>='3.5'
pre-commit
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import pytest
import simplejson as json
import yaml
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from six import iteritems
from six import iterkeys
from six.moves.urllib import parse as urlparse
Expand Down
5 changes: 4 additions & 1 deletion tests/formatter/to_python_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from datetime import datetime

import six
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from bravado_core.formatter import SwaggerFormat
from bravado_core.formatter import to_python
Expand Down
5 changes: 4 additions & 1 deletion tests/formatter/to_wire_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

import pytest
import six
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch
from pytz import timezone

from bravado_core.exception import SwaggerMappingError
Expand Down
5 changes: 4 additions & 1 deletion tests/model/bless_models_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core.model import _bless_models
Expand Down
5 changes: 4 additions & 1 deletion tests/model/create_model_type_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core.model import create_model_type
Expand Down
5 changes: 4 additions & 1 deletion tests/model/get_model_name_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core.model import _get_model_name
Expand Down
5 changes: 4 additions & 1 deletion tests/model/model_discovery_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core.model import _run_post_processing
Expand Down
5 changes: 4 additions & 1 deletion tests/model/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from copy import deepcopy

import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from six import add_metaclass

from bravado_core.content_type import APP_JSON
Expand Down
5 changes: 4 additions & 1 deletion tests/model/post_process_spec_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import functools

from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.model import _post_process_spec
from bravado_core.spec import Spec
Expand Down
5 changes: 4 additions & 1 deletion tests/model/tag_models_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import copy

import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core import model
Expand Down
5 changes: 4 additions & 1 deletion tests/operation/security_object_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
from six import iteritems

from bravado_core.exception import SwaggerSchemaError
Expand Down
5 changes: 4 additions & 1 deletion tests/param/add_file_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.exception import SwaggerMappingError
from bravado_core.operation import Operation
Expand Down
5 changes: 4 additions & 1 deletion tests/param/cast_request_param_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from bravado_core.param import cast_request_param

Expand Down
5 changes: 4 additions & 1 deletion tests/param/get_param_type_spec_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.exception import SwaggerMappingError
from bravado_core.operation import Operation
Expand Down
6 changes: 4 additions & 2 deletions tests/param/marshal_param_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import pytest
from jsonschema import ValidationError
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.content_type import APP_JSON
from bravado_core.operation import Operation
Expand Down
6 changes: 4 additions & 2 deletions tests/param/unmarshal_param_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import datetime

import pytest
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.operation import Operation
from bravado_core.param import Param
Expand Down
5 changes: 4 additions & 1 deletion tests/request/unmarshal_request_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.exception import SwaggerMappingError
from bravado_core.operation import Operation
Expand Down
6 changes: 4 additions & 2 deletions tests/response/unmarshal_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import msgpack
import pytest
from jsonschema import ValidationError
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.content_type import APP_JSON
from bravado_core.content_type import APP_MSGPACK
Expand Down
5 changes: 4 additions & 1 deletion tests/response/validate_response_body_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import msgpack
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.content_type import APP_MSGPACK
from bravado_core.exception import SwaggerMappingError
Expand Down
5 changes: 4 additions & 1 deletion tests/response/validate_response_headers_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from jsonschema.exceptions import ValidationError
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado_core.operation import Operation
from bravado_core.response import OutgoingResponse
Expand Down
6 changes: 4 additions & 2 deletions tests/response/validate_response_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.operation import Operation
from bravado_core.response import OutgoingResponse
Expand Down
6 changes: 4 additions & 2 deletions tests/spec/Spec/build_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch
from six import iterkeys
from six.moves.urllib.request import pathname2url
from swagger_spec_validator.common import SwaggerValidationError
Expand Down
5 changes: 4 additions & 1 deletion tests/spec/Spec/flattened_spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import functools
import os

import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest
from six.moves.urllib.parse import urlparse
from swagger_spec_validator import validator20
Expand Down
5 changes: 4 additions & 1 deletion tests/spec/build_http_handlers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import json
from io import StringIO

import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest
import yaml

Expand Down
5 changes: 4 additions & 1 deletion tests/spec/pickling_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest
from six.moves.cPickle import dumps
from six.moves.cPickle import loads
Expand Down
6 changes: 4 additions & 2 deletions tests/swagger20_validator/enum_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from jsonschema import ValidationError
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.spec import Spec
from bravado_core.swagger20_validator import enum_validator
Expand Down
5 changes: 4 additions & 1 deletion tests/swagger20_validator/format_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from jsonschema import ValidationError
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from bravado_core.exception import SwaggerValidationError
from bravado_core.formatter import SwaggerFormat
Expand Down
6 changes: 4 additions & 2 deletions tests/swagger20_validator/ref_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from jsonschema.validators import RefResolver
from mock import MagicMock
from mock import Mock
try:
from unittest.mock import MagicMock, Mock
except ImportError:
from mock import MagicMock, Mock

from bravado_core.swagger20_validator import ref_validator

Expand Down
6 changes: 4 additions & 2 deletions tests/swagger20_validator/required_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from jsonschema.exceptions import ValidationError
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado_core.swagger20_validator import required_validator

Expand Down
5 changes: 4 additions & 1 deletion tests/swagger20_validator/type_validator_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# -*- coding: utf-8 -*-
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from bravado_core.swagger20_validator import type_validator

Expand Down
5 changes: 4 additions & 1 deletion tests/util_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
from inspect import getcallargs

import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest

from bravado_core.util import AliasKeyDict
Expand Down

0 comments on commit 4776d58

Please sign in to comment.