Skip to content

Commit f3ebbae

Browse files
majoracocuzzoparthea
authored
test: import mock via unittest.mock (#702)
* Import mock via unittest.mock The `mock` module is deprecated and modern versions of Python havd `mock` available in the `unittest` standard library. Fixes: #701 Signed-off-by: Major Hayden <major@mhtx.net> Co-authored-by: Anna Cocuzzo <63511057+acocuzzo@users.noreply.github.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 0fa30c1 commit f3ebbae

17 files changed

+118
-17
lines changed

tests/system.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
import operator as op
2121
import os
2222
import psutil
23+
import sys
2324
import threading
2425
import time
2526

26-
import mock
27+
# special case python < 3.8
28+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
29+
import mock
30+
else:
31+
from unittest import mock
32+
2733
import pytest
2834

2935
import google.auth

tests/unit/pubsub_v1/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
1415

1516
import google.auth.credentials
16-
import mock
17+
18+
# special case python < 3.8
19+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
20+
import mock
21+
else:
22+
from unittest import mock
23+
1724
import pytest
1825

1926

tests/unit/pubsub_v1/publisher/batch/test_base.py

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

1515
from __future__ import absolute_import
16+
import sys
1617

17-
import mock
18+
# special case python < 3.8
19+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
20+
import mock
21+
else:
22+
from unittest import mock
1823

1924
from google.auth import credentials
2025
from google.cloud.pubsub_v1 import publisher

tests/unit/pubsub_v1/publisher/batch/test_thread.py

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

1515
import datetime
16+
import sys
1617
import threading
1718
import time
1819

19-
import mock
20+
# special case python < 3.8
21+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
22+
import mock
23+
else:
24+
from unittest import mock
25+
2026
import pytest
2127

2228
import google.api_core.exceptions

tests/unit/pubsub_v1/publisher/sequencer/test_ordered_sequencer.py

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

1515
import concurrent.futures as futures
16-
import mock
16+
import sys
17+
18+
# special case python < 3.8
19+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
20+
import mock
21+
else:
22+
from unittest import mock
23+
1724
import pytest
1825

1926
from google.auth import credentials

tests/unit/pubsub_v1/publisher/sequencer/test_unordered_sequencer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
15+
16+
# special case python < 3.8
17+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
18+
import mock
19+
else:
20+
from unittest import mock
1421

15-
import mock
1622
import pytest
1723

1824
from google.auth import credentials

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616
from __future__ import division
1717

1818
import inspect
19+
import sys
1920

2021
import grpc
2122

22-
import mock
23+
# special case python < 3.8
24+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
25+
import mock
26+
else:
27+
from unittest import mock
28+
2329
import pytest
2430
import time
2531
import warnings

tests/unit/pubsub_v1/subscriber/test_dispatcher.py

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

1515
import collections
1616
import queue
17+
import sys
1718
import threading
1819

1920
from google.cloud.pubsub_v1.subscriber._protocol import dispatcher
@@ -22,7 +23,12 @@
2223
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
2324
from google.cloud.pubsub_v1.subscriber import futures
2425

25-
import mock
26+
# special case python < 3.8
27+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
28+
import mock
29+
else:
30+
from unittest import mock
31+
2632
import pytest
2733
from google.cloud.pubsub_v1.subscriber.exceptions import (
2834
AcknowledgeStatus,

tests/unit/pubsub_v1/subscriber/test_futures_subscriber.py

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

1515
from __future__ import absolute_import
16+
import sys
17+
18+
# special case python < 3.8
19+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
20+
import mock
21+
else:
22+
from unittest import mock
1623

17-
import mock
1824
import pytest
1925

2026
from google.cloud.pubsub_v1.subscriber import futures

tests/unit/pubsub_v1/subscriber/test_heartbeater.py

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

1515
import logging
16+
import sys
1617
import threading
1718

1819
from google.cloud.pubsub_v1.subscriber._protocol import heartbeater
1920
from google.cloud.pubsub_v1.subscriber._protocol import streaming_pull_manager
2021

21-
import mock
22+
# special case python < 3.8
23+
if sys.version_info.major == 3 and sys.version_info.minor < 8:
24+
import mock
25+
else:
26+
from unittest import mock
27+
2228
import pytest
2329

2430

0 commit comments

Comments
 (0)