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

fix: Switch to unittest.mock from mock #713

Merged
merged 7 commits into from
Oct 9, 2024
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
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal

session.install(
"dataclasses",
"mock",
"mock; python_version=='3.7'",
"pytest",
"pytest-cov",
"pytest-xdist",
Expand Down Expand Up @@ -280,8 +280,8 @@ def mypy(session):
"types-setuptools",
"types-requests",
"types-protobuf",
"types-mock",
"types-dataclasses",
"types-mock; python_version=='3.7'",
)
session.run("mypy", "google", "tests")

Expand Down
2 changes: 1 addition & 1 deletion tests/asyncio/future/test_async_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import asyncio
from unittest import mock

import mock
import pytest

from google.api_core import exceptions
Expand Down
6 changes: 5 additions & 1 deletion tests/asyncio/gapic/test_method_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

import datetime

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore
import pytest

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

import pytest

try:
Expand Down
9 changes: 7 additions & 2 deletions tests/asyncio/retry/test_retry_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
import datetime
import re
import asyncio

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

import pytest

from google.api_core import exceptions
Expand Down
6 changes: 5 additions & 1 deletion tests/asyncio/retry/test_retry_unary_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import datetime
import re

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore
import pytest

from google.api_core import exceptions
Expand Down
6 changes: 5 additions & 1 deletion tests/asyncio/test_grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore
import pytest # noqa: I202

try:
Expand Down
7 changes: 6 additions & 1 deletion tests/asyncio/test_operation_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
# limitations under the License.


import mock
import pytest

try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

try:
import grpc # noqa: F401
except ImportError: # pragma: NO COVER
Expand Down
6 changes: 5 additions & 1 deletion tests/asyncio/test_page_iterator_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

import inspect

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore
import pytest

from google.api_core import page_iterator_async
Expand Down
11 changes: 8 additions & 3 deletions tests/asyncio/test_rest_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@
# TODO: set random.seed explicitly in each test function.
# See related issue: https://github.com/googleapis/python-api-core/issues/689.

import pytest # noqa: I202
import mock

import datetime
import logging
import random
import time
from typing import List, AsyncIterator

try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

import pytest # noqa: I202

import proto

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

import mock
from unittest import mock

from google.api_core.future import _helpers

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/future/test_polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import concurrent.futures
import threading
import time
from unittest import mock

import mock
import pytest

from google.api_core import exceptions, retry
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/gapic/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import datetime
from unittest import mock

import mock
import pytest

try:
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/operations_v1/test_operations_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
#
import os

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

import pytest
from typing import Any, List

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/retry/test_retry_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import itertools
import re
from unittest import mock

import mock
import pytest
import requests.exceptions

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/retry/test_retry_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

import re

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

import pytest

from google.api_core import exceptions
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/retry/test_retry_unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
# limitations under the License.

import datetime
import pytest
import re

import mock
import pytest
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

from google.api_core import exceptions
from google.api_core import retry
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/test_bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
import queue
import threading

import mock
try:
from unittest import mock
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
except ImportError: # pragma: NO COVER
import mock # type: ignore

import pytest

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import http.client
import json
from unittest import mock

import mock
import pytest
import requests

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_extended_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import dataclasses
import enum
import typing
from unittest import mock

import mock
import pytest

from google.api_core import exceptions
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

import pytest

try:
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# limitations under the License.


import mock
from unittest import mock

import pytest

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_page_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import math
import types
from unittest import mock

import mock
import pytest

from google.api_core import page_iterator
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_path_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

from __future__ import unicode_literals
from unittest import mock

import mock
import pytest

from google.api import auth_pb2
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import datetime
import itertools

import mock
from unittest import mock

from google.api_core import timeout as timeouts

Expand Down