Skip to content

Commit 6018598

Browse files
partheachalmerlowe
andauthored
chore: use mock from unittest (#1823)
* chore: use mock from unittest * correct user_credentials_test.py * add try except for Python 3.7 * fixes linting * adjustments to testing suite to account for dependencies * updates to mypy_samples.py * linting for noxfile.py --------- Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
1 parent 135a23d commit 6018598

32 files changed

Lines changed: 77 additions & 65 deletions

packages/google-cloud-bigquery/noxfile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def default(session, install_extras=True):
7272

7373
# Install all test dependencies, then install local packages in-place.
7474
session.install(
75-
"mock",
7675
"pytest",
7776
"google-cloud-testutils",
7877
"pytest-cov",
@@ -89,6 +88,8 @@ def default(session, install_extras=True):
8988
install_target = "."
9089
session.install("-e", install_target, "-c", constraints_path)
9190

91+
session.run("python", "-m", "pip", "freeze")
92+
9293
# Run py.test against the unit tests.
9394
session.run(
9495
"py.test",
@@ -176,7 +177,7 @@ def system(session):
176177

177178
# Install all test dependencies, then install local packages in place.
178179
session.install(
179-
"mock", "pytest", "psutil", "google-cloud-testutils", "-c", constraints_path
180+
"pytest", "psutil", "google-cloud-testutils", "-c", constraints_path
180181
)
181182
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "") == "true":
182183
# mTLS test requires pyopenssl and latest google-cloud-storage
@@ -249,7 +250,7 @@ def snippets(session):
249250
)
250251

251252
# Install all test dependencies, then install local packages in place.
252-
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
253+
session.install("pytest", "google-cloud-testutils", "-c", constraints_path)
253254
session.install("google-cloud-storage", "-c", constraints_path)
254255
session.install("grpcio", "-c", constraints_path)
255256

@@ -336,7 +337,6 @@ def prerelease_deps(session):
336337
"google-cloud-datacatalog",
337338
"google-cloud-storage",
338339
"google-cloud-testutils",
339-
"mock",
340340
"psutil",
341341
"pytest",
342342
"pytest-cov",

packages/google-cloud-bigquery/samples/desktopapp/user_credentials_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@
1313
# limitations under the License.
1414

1515
import os
16+
import sys
1617
from typing import Iterator, Union
18+
from unittest import mock
1719

1820
import google.auth
19-
import mock
2021
import pytest
2122

2223
from .user_credentials import main # type: ignore
2324

2425
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
2526

26-
MockType = Union[mock.mock.MagicMock, mock.mock.AsyncMock]
27+
28+
if sys.version_info >= (3, 8):
29+
# Python 3.8+ has an AsyncMock attribute in unittest.mock, but 3.7 does not
30+
MockType = Union[mock.MagicMock, mock.AsyncMock]
31+
else:
32+
# Other definitions and imports
33+
MockType = Union[mock.MagicMock]
2734

2835

2936
@pytest.fixture

packages/google-cloud-bigquery/samples/tests/conftest.py

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

1515
import datetime
1616
from typing import Iterator, List
17+
from unittest import mock
1718
import uuid
1819

1920
import google.auth
20-
import mock
2121
import pytest
2222

2323
from google.cloud import bigquery

packages/google-cloud-bigquery/testing/constraints-3.7.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
# Then this file should have foo==1.14.0
88
db-dtypes==0.3.0
99
geopandas==0.9.0
10-
google-api-core==1.31.5
11-
google-cloud-bigquery-storage==2.6.0
12-
google-cloud-core==1.6.0
13-
google-resumable-media==0.6.0
10+
google-api-core==2.17.1
11+
google-auth==2.28.1
12+
google-cloud-bigquery-storage==2.24.0
13+
google-cloud-core==2.4.1
14+
google-cloud-testutils==1.4.0
15+
google-crc32c==1.5.0
16+
google-resumable-media==2.7.0
17+
googleapis-common-protos==1.62.0
1418
grpcio==1.47.0
19+
grpcio-status==1.47.0
1520
ipywidgets==7.7.1
1621
ipython==7.23.1
1722
ipykernel==6.0.0

packages/google-cloud-bigquery/tests/unit/conftest.py

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

15-
import mock
15+
from unittest import mock
16+
1617
import pytest
1718

1819
from .helpers import make_client

packages/google-cloud-bigquery/tests/unit/helpers.py

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

15+
from unittest import mock
16+
17+
import pytest
18+
1519
import google.cloud.bigquery.client
1620
import google.cloud.bigquery.dataset
17-
import mock
18-
import pytest
1921

2022

2123
def make_connection(*responses):
2224
import google.cloud.bigquery._http
23-
import mock
2425
from google.cloud.exceptions import NotFound
2526

2627
mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)

packages/google-cloud-bigquery/tests/unit/job/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import copy
1616
import http
1717
import unittest
18+
from unittest import mock
1819

1920
from google.api_core import exceptions
2021
import google.api_core.retry
2122
from google.api_core.future import polling
22-
import mock
2323
import pytest
2424

2525
from ..helpers import make_connection

packages/google-cloud-bigquery/tests/unit/job/test_copy.py

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

15-
import mock
15+
from unittest import mock
1616

1717
from ..helpers import make_connection
1818

packages/google-cloud-bigquery/tests/unit/job/test_extract.py

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

15-
import mock
15+
from unittest import mock
1616

1717
from ..helpers import make_connection
1818

packages/google-cloud-bigquery/tests/unit/job/test_load.py

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

1515
import copy
16-
17-
import mock
16+
from unittest import mock
1817

1918
from ..helpers import make_connection
2019

0 commit comments

Comments
 (0)