Skip to content

Commit

Permalink
test: Switch to unittest.mock from mock
Browse files Browse the repository at this point in the history
Now that the minimum supported version of Python is 3.7, we can stop
using the external mock requirement, and import it from unittest. I have
also attempted to keep imports ordered.

Fixes #377
  • Loading branch information
s-t-e-v-e-n-k committed Oct 2, 2024
1 parent 84bf637 commit 5f28e21
Show file tree
Hide file tree
Showing 25 changed files with 32 additions and 30 deletions.
2 changes: 0 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal

session.install(
"dataclasses",
"mock",
"pytest",
"pytest-cov",
"pytest-xdist",
Expand Down Expand Up @@ -280,7 +279,6 @@ def mypy(session):
"types-setuptools",
"types-requests",
"types-protobuf",
"types-mock",
"types-dataclasses",
)
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
2 changes: 1 addition & 1 deletion tests/asyncio/gapic/test_method_async.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
3 changes: 2 additions & 1 deletion tests/asyncio/operations_v1/test_operations_async_client.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
4 changes: 2 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,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
import datetime
import re
import asyncio
from unittest import mock

import mock
import pytest

from google.api_core import exceptions
Expand Down
2 changes: 1 addition & 1 deletion tests/asyncio/retry/test_retry_unary_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import datetime
import re
from unittest import mock

import mock
import pytest

from google.api_core import exceptions
Expand Down
3 changes: 2 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,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

import pytest # noqa: I202

try:
Expand Down
3 changes: 2 additions & 1 deletion tests/asyncio/test_operation_async.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/asyncio/test_page_iterator_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import inspect
from unittest import mock

import mock
import pytest

from google.api_core import page_iterator_async
Expand Down
6 changes: 3 additions & 3 deletions tests/asyncio/test_rest_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
# 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
from unittest import mock

import pytest # noqa: I202

import proto

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
2 changes: 1 addition & 1 deletion tests/unit/operations_v1/test_operations_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# limitations under the License.
#
import os
from unittest import mock

import mock
import pytest

try:
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
2 changes: 1 addition & 1 deletion tests/unit/retry/test_retry_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import re
from unittest import mock

import mock
import pytest

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

import datetime
import re
from unittest import mock

import mock
import pytest

from google.api_core import exceptions
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import logging
import queue
import threading
from unittest import mock

import mock
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

0 comments on commit 5f28e21

Please sign in to comment.