From afc2462a0230af923ea9912798d6e0fdcc7b532e Mon Sep 17 00:00:00 2001
From: Major Hayden <major@mhtx.net>
Date: Tue, 15 Jun 2021 09:07:51 -0500
Subject: [PATCH] Bug: Use unittest.mock if it is available
The python mock module is deprecated in recent Python versions. If
unittest.mock is available in the system's python, use that instead.
Fixes: #207
Signed-off-by: Major Hayden <major@mhtx.net>
---
tests/asyncio/future/test_async_future.py | 5 ++++-
tests/asyncio/gapic/test_method_async.py | 5 ++++-
tests/asyncio/operations_v1/test_operations_async_client.py | 5 ++++-
tests/asyncio/test_grpc_helpers_async.py | 5 ++++-
tests/asyncio/test_operation_async.py | 5 ++++-
tests/asyncio/test_page_iterator_async.py | 5 ++++-
tests/asyncio/test_retry_async.py | 5 ++++-
tests/unit/future/test__helpers.py | 5 ++++-
tests/unit/future/test_polling.py | 5 ++++-
tests/unit/gapic/test_method.py | 5 ++++-
tests/unit/test_bidi.py | 5 ++++-
tests/unit/test_exceptions.py | 5 ++++-
tests/unit/test_grpc_helpers.py | 5 ++++-
tests/unit/test_operation.py | 5 ++++-
tests/unit/test_page_iterator.py | 5 ++++-
tests/unit/test_path_template.py | 5 ++++-
tests/unit/test_retry.py | 5 ++++-
tests/unit/test_timeout.py | 5 ++++-
18 files changed, 72 insertions(+), 18 deletions(-)
diff --git a/tests/asyncio/future/test_async_future.py b/tests/asyncio/future/test_async_future.py
index 3322cb0..cd50b6f 100644
--- a/tests/asyncio/future/test_async_future.py
+++ b/tests/asyncio/future/test_async_future.py
@@ -14,7 +14,10 @@
import asyncio
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions
diff --git a/tests/asyncio/gapic/test_method_async.py b/tests/asyncio/gapic/test_method_async.py
index 7318362..1c12a67 100644
--- a/tests/asyncio/gapic/test_method_async.py
+++ b/tests/asyncio/gapic/test_method_async.py
@@ -15,7 +15,10 @@
import datetime
from grpc.experimental import aio
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import (exceptions, gapic_v1, grpc_helpers_async,
diff --git a/tests/asyncio/operations_v1/test_operations_async_client.py b/tests/asyncio/operations_v1/test_operations_async_client.py
index a646901..1b0e3d0 100644
--- a/tests/asyncio/operations_v1/test_operations_async_client.py
+++ b/tests/asyncio/operations_v1/test_operations_async_client.py
@@ -13,7 +13,10 @@
# limitations under the License.
from grpc.experimental import aio
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import (grpc_helpers_async, operations_v1,
diff --git a/tests/asyncio/test_grpc_helpers_async.py b/tests/asyncio/test_grpc_helpers_async.py
index 868018c..312c54b 100644
--- a/tests/asyncio/test_grpc_helpers_async.py
+++ b/tests/asyncio/test_grpc_helpers_async.py
@@ -14,7 +14,10 @@
import grpc
from grpc.experimental import aio
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions
diff --git a/tests/asyncio/test_operation_async.py b/tests/asyncio/test_operation_async.py
index e35d139..9b2294c 100644
--- a/tests/asyncio/test_operation_async.py
+++ b/tests/asyncio/test_operation_async.py
@@ -13,7 +13,10 @@
# limitations under the License.
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions
diff --git a/tests/asyncio/test_page_iterator_async.py b/tests/asyncio/test_page_iterator_async.py
index 4abacc6..25fb76f 100644
--- a/tests/asyncio/test_page_iterator_async.py
+++ b/tests/asyncio/test_page_iterator_async.py
@@ -14,7 +14,10 @@
import inspect
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import page_iterator_async
diff --git a/tests/asyncio/test_retry_async.py b/tests/asyncio/test_retry_async.py
index 8f86366..1656669 100644
--- a/tests/asyncio/test_retry_async.py
+++ b/tests/asyncio/test_retry_async.py
@@ -15,7 +15,10 @@
import datetime
import re
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions
diff --git a/tests/unit/future/test__helpers.py b/tests/unit/future/test__helpers.py
index 98afc59..1d15e66 100644
--- a/tests/unit/future/test__helpers.py
+++ b/tests/unit/future/test__helpers.py
@@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
from google.api_core.future import _helpers
diff --git a/tests/unit/future/test_polling.py b/tests/unit/future/test_polling.py
index 2381d03..cc59744 100644
--- a/tests/unit/future/test_polling.py
+++ b/tests/unit/future/test_polling.py
@@ -16,7 +16,10 @@
import threading
import time
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions, retry
diff --git a/tests/unit/gapic/test_method.py b/tests/unit/gapic/test_method.py
index 1ae27de..9ab7b39 100644
--- a/tests/unit/gapic/test_method.py
+++ b/tests/unit/gapic/test_method.py
@@ -14,7 +14,10 @@
import datetime
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
from google.api_core import exceptions
from google.api_core import retry
diff --git a/tests/unit/test_bidi.py b/tests/unit/test_bidi.py
index 52215cb..9f49751 100644
--- a/tests/unit/test_bidi.py
+++ b/tests/unit/test_bidi.py
@@ -17,7 +17,10 @@
import threading
import grpc
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from six.moves import queue
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
index fb29015..c6d4d80 100644
--- a/tests/unit/test_exceptions.py
+++ b/tests/unit/test_exceptions.py
@@ -15,7 +15,10 @@
import json
import grpc
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import requests
from six.moves import http_client
diff --git a/tests/unit/test_grpc_helpers.py b/tests/unit/test_grpc_helpers.py
index 8c6202b..9bb3756 100644
--- a/tests/unit/test_grpc_helpers.py
+++ b/tests/unit/test_grpc_helpers.py
@@ -13,7 +13,10 @@
# limitations under the License.
import grpc
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import exceptions
diff --git a/tests/unit/test_operation.py b/tests/unit/test_operation.py
index ae9bafe..d3f0e42 100644
--- a/tests/unit/test_operation.py
+++ b/tests/unit/test_operation.py
@@ -13,7 +13,10 @@
# limitations under the License.
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
from google.api_core import exceptions
from google.api_core import operation
diff --git a/tests/unit/test_page_iterator.py b/tests/unit/test_page_iterator.py
index 97b0657..d78d250 100644
--- a/tests/unit/test_page_iterator.py
+++ b/tests/unit/test_page_iterator.py
@@ -15,7 +15,10 @@
import math
import types
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
import six
diff --git a/tests/unit/test_path_template.py b/tests/unit/test_path_template.py
index 4c8a7c5..4dae898 100644
--- a/tests/unit/test_path_template.py
+++ b/tests/unit/test_path_template.py
@@ -14,7 +14,10 @@
from __future__ import unicode_literals
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
from google.api_core import path_template
diff --git a/tests/unit/test_retry.py b/tests/unit/test_retry.py
index ce8f417..758648e 100644
--- a/tests/unit/test_retry.py
+++ b/tests/unit/test_retry.py
@@ -16,7 +16,10 @@
import itertools
import re
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
import pytest
import requests.exceptions
diff --git a/tests/unit/test_timeout.py b/tests/unit/test_timeout.py
index 30d624e..01d0e5b 100644
--- a/tests/unit/test_timeout.py
+++ b/tests/unit/test_timeout.py
@@ -15,7 +15,10 @@
import datetime
import itertools
-import mock
+try:
+ from unittest import mock
+except:
+ import mock
from google.api_core import timeout