Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard library mock when possible #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/source/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ First of all, in order to make sure your code doesn't do any network requests, y

.. code-block:: python

import mock
from unittest import mock
import pytest

from bravado.client import SwaggerClient
Expand All @@ -46,7 +46,7 @@ Now we can mock out that call to ``findPetsByStatus`` by using the

.. code-block:: python

import mock
from unittest import mock

from bravado.testing.response_mocks import BravadoResponseMock

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bottle
ephemeral_port_reserve
httpretty
mock
mock; python_version<'3.3'
pip>=9.0.1 # workaround to https://github.com/pypa/pip/issues/3903
pre-commit
pytest<4.7 # need support for Python 2.7, see https://docs.pytest.org/en/latest/py27-py34-deprecation.html
Expand Down
5 changes: 4 additions & 1 deletion tests/client/construct_params_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import pytest
from bravado_core.exception import SwaggerMappingError
from bravado_core.operation import Operation
from mock import patch
try:
from unittest.mock import patch
except ImportError:
from mock import patch

from bravado.client import CallableOperation
from bravado.client import construct_params
Expand Down
5 changes: 4 additions & 1 deletion tests/client/construct_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from typing import Any
from typing import Dict

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

from bravado.client import inject_headers_for_remote_refs

Expand Down
5 changes: 4 additions & 1 deletion tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import typing
from copy import deepcopy

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

from bravado.client import SwaggerClient
Expand Down
5 changes: 4 additions & 1 deletion tests/config_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.config import _get_response_metadata_class
Expand Down
16 changes: 9 additions & 7 deletions tests/fido_client/FidoClient/request_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
import mock
from mock import patch
try:
from unittest import mock
except ImportError:
import mock

from bravado.fido_client import FidoClient


def test_request_no_timeouts_passed_to_fido():
with patch('bravado.fido_client.fido.fetch') as fetch:
with mock.patch('bravado.fido_client.fido.fetch') as fetch:
request_params = dict(url='http://foo.com/')
FidoClient().request(request_params)
assert fetch.call_args == mock.call(
Expand All @@ -18,7 +20,7 @@ def test_request_no_timeouts_passed_to_fido():


def test_request_timeout_passed_to_fido():
with patch('bravado.fido_client.fido.fetch') as fetch:
with mock.patch('bravado.fido_client.fido.fetch') as fetch:
request_params = dict(url='http://foo.com/', timeout=1)
FidoClient().request(request_params)
assert fetch.call_args == mock.call(
Expand All @@ -31,7 +33,7 @@ def test_request_timeout_passed_to_fido():


def test_request_connect_timeout_passed_to_fido():
with patch('bravado.fido_client.fido.fetch') as fetch:
with mock.patch('bravado.fido_client.fido.fetch') as fetch:
request_params = dict(url='http://foo.com/', connect_timeout=1)
FidoClient().request(request_params)
assert fetch.call_args == mock.call(
Expand All @@ -44,7 +46,7 @@ def test_request_connect_timeout_passed_to_fido():


def test_request_connect_timeout_and_timeout_passed_to_fido():
with patch('bravado.fido_client.fido.fetch') as fetch:
with mock.patch('bravado.fido_client.fido.fetch') as fetch:
request_params = dict(url='http://foo.com/', connect_timeout=1,
timeout=2)
FidoClient().request(request_params)
Expand All @@ -59,7 +61,7 @@ def test_request_connect_timeout_and_timeout_passed_to_fido():


def test_request_tcp_nodeley_passed_to_fido():
with patch('bravado.fido_client.fido.fetch') as fetch:
with mock.patch('bravado.fido_client.fido.fetch') as fetch:
request_params = dict(url='http://foo.com/', tcp_nodelay=True)
FidoClient().request(request_params)
assert fetch.call_args == mock.call(
Expand Down
5 changes: 4 additions & 1 deletion tests/fido_client/FidoFutureAdapter/result_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import crochet
import fido.exceptions
import pytest
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado.fido_client import FidoFutureAdapter

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

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

from bravado.fido_client import FidoResponseAdapter

Expand Down
5 changes: 4 additions & 1 deletion tests/http_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import unittest

import httpretty
import mock
try:
from unittest import mock
except ImportError:
import mock
import pytest
import requests
from bravado_core.response import IncomingResponse
Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/HttpFuture/cancel_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.response import IncomingResponse

Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/HttpFuture/conftest.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.http_future import FutureAdapter
Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/HttpFuture/response_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.response import IncomingResponse

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

from bravado.config import RequestConfig
from bravado.exception import HTTPError
Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/raise_on_expected_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from bravado_core.response import IncomingResponse
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado.exception import HTTPError
from bravado.http_future import raise_on_expected
Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/raise_on_unexpected_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import pytest
from bravado_core.response import IncomingResponse
from mock import Mock
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock

from bravado.exception import HTTPError
from bravado.http_future import raise_on_unexpected
Expand Down
5 changes: 4 additions & 1 deletion tests/http_future/unmarshall_response_inner_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 msgpack
import pytest
from bravado_core.content_type import APP_JSON
Expand Down
6 changes: 4 additions & 2 deletions tests/http_future/unmarshall_response_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from bravado_core.exception import MatchingResponseNotFound
from bravado_core.operation import Operation
from bravado_core.response import IncomingResponse
from mock import Mock
from mock import patch
try:
from unittest.mock import Mock, patch
except ImportError:
from mock import Mock, patch

from bravado.exception import HTTPError
from bravado.http_future import unmarshal_response
Expand Down
5 changes: 4 additions & 1 deletion tests/requests_client/RequestsFutureAdapter/conftest.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 requests.sessions import Session


Expand Down
5 changes: 4 additions & 1 deletion tests/response_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

from bravado.config import RequestConfig
from bravado.response import BravadoResponseMetadata
Expand Down
6 changes: 5 additions & 1 deletion tests/testing/response_mocks_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*-
import inspect

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

import pytest
from bravado_core.response import IncomingResponse

Expand Down
6 changes: 4 additions & 2 deletions tests/warning/warn_for_deprecated_op_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.client import CallableOperation
from bravado.warning import warn_for_deprecated_op
Expand Down