Skip to content

Commit 169bd99

Browse files
committed
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. Signed-off-by: Major Hayden <[email protected]>
1 parent 11032cf commit 169bd99

18 files changed

+72
-18
lines changed

tests/asyncio/future/test_async_future.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
import asyncio
1616

17-
import mock
17+
try:
18+
from unittest import mock
19+
except:
20+
import mock
1821
import pytest
1922

2023
from google.api_core import exceptions

tests/asyncio/gapic/test_method_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import datetime
1616

1717
from grpc.experimental import aio
18-
import mock
18+
try:
19+
from unittest import mock
20+
except:
21+
import mock
1922
import pytest
2023

2124
from google.api_core import (exceptions, gapic_v1, grpc_helpers_async,

tests/asyncio/operations_v1/test_operations_async_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# limitations under the License.
1414

1515
from grpc.experimental import aio
16-
import mock
16+
try:
17+
from unittest import mock
18+
except:
19+
import mock
1720
import pytest
1821

1922
from google.api_core import (grpc_helpers_async, operations_v1,

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
import grpc
1616
from grpc.experimental import aio
17-
import mock
17+
try:
18+
from unittest import mock
19+
except:
20+
import mock
1821
import pytest
1922

2023
from google.api_core import exceptions

tests/asyncio/test_operation_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# limitations under the License.
1414

1515

16-
import mock
16+
try:
17+
from unittest import mock
18+
except:
19+
import mock
1720
import pytest
1821

1922
from google.api_core import exceptions

tests/asyncio/test_page_iterator_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
import inspect
1616

17-
import mock
17+
try:
18+
from unittest import mock
19+
except:
20+
import mock
1821
import pytest
1922

2023
from google.api_core import page_iterator_async

tests/asyncio/test_retry_async.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import datetime
1616
import re
1717

18-
import mock
18+
try:
19+
from unittest import mock
20+
except:
21+
import mock
1922
import pytest
2023

2124
from google.api_core import exceptions

tests/unit/future/test__helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
try:
16+
from unittest import mock
17+
except:
18+
import mock
1619

1720
from google.api_core.future import _helpers
1821

tests/unit/future/test_polling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import threading
1717
import time
1818

19-
import mock
19+
try:
20+
from unittest import mock
21+
except:
22+
import mock
2023
import pytest
2124

2225
from google.api_core import exceptions, retry

tests/unit/gapic/test_method.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
import datetime
1616

17-
import mock
17+
try:
18+
from unittest import mock
19+
except:
20+
import mock
1821

1922
from google.api_core import exceptions
2023
from google.api_core import retry

tests/unit/test_bidi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
import threading
1818

1919
import grpc
20-
import mock
20+
try:
21+
from unittest import mock
22+
except:
23+
import mock
2124
import pytest
2225
from six.moves import queue
2326

tests/unit/test_exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import json
1616

1717
import grpc
18-
import mock
18+
try:
19+
from unittest import mock
20+
except:
21+
import mock
1922
import requests
2023
from six.moves import http_client
2124

tests/unit/test_grpc_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# limitations under the License.
1414

1515
import grpc
16-
import mock
16+
try:
17+
from unittest import mock
18+
except:
19+
import mock
1720
import pytest
1821

1922
from google.api_core import exceptions

tests/unit/test_operation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# limitations under the License.
1414

1515

16-
import mock
16+
try:
17+
from unittest import mock
18+
except:
19+
import mock
1720

1821
from google.api_core import exceptions
1922
from google.api_core import operation

tests/unit/test_page_iterator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import math
1616
import types
1717

18-
import mock
18+
try:
19+
from unittest import mock
20+
except:
21+
import mock
1922
import pytest
2023
import six
2124

tests/unit/test_path_template.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
from __future__ import unicode_literals
1616

17-
import mock
17+
try:
18+
from unittest import mock
19+
except:
20+
import mock
1821
import pytest
1922

2023
from google.api_core import path_template

tests/unit/test_retry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import itertools
1717
import re
1818

19-
import mock
19+
try:
20+
from unittest import mock
21+
except:
22+
import mock
2023
import pytest
2124
import requests.exceptions
2225

tests/unit/test_timeout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import datetime
1616
import itertools
1717

18-
import mock
18+
try:
19+
from unittest import mock
20+
except:
21+
import mock
1922

2023
from google.api_core import timeout
2124

0 commit comments

Comments
 (0)