GeezerVison is showing github.com — chore: use mock from unittest (#1823) · kiraksi/python-bigquery@08762fb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: noxfile.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,7 +72,6 @@ def default(session, install_extras=True): | 72 | 72 |
| 73 | 73 | # Install all test dependencies, then install local packages in-place. | 74 | 74 | session.install( | 75 | | - "mock", | 76 | 75 | "pytest", | 77 | 76 | "google-cloud-testutils", | 78 | 77 | "pytest-cov", | @@ -89,6 +88,8 @@ def default(session, install_extras=True): | 89 | 88 | install_target = "." | 90 | 89 | session.install("-e", install_target, "-c", constraints_path) | 91 | 90 |
| | 91 | + session.run("python", "-m", "pip", "freeze") | | 92 | + | 92 | 93 | # Run py.test against the unit tests. | 93 | 94 | session.run( | 94 | 95 | "py.test", | @@ -176,7 +177,7 @@ def system(session): | 176 | 177 |
| 177 | 178 | # Install all test dependencies, then install local packages in place. | 178 | 179 | session.install( | 179 | | - "mock", "pytest", "psutil", "google-cloud-testutils", "-c", constraints_path | | 180 | + "pytest", "psutil", "google-cloud-testutils", "-c", constraints_path | 180 | 181 | ) | 181 | 182 | if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "") == "true": | 182 | 183 | # mTLS test requires pyopenssl and latest google-cloud-storage | @@ -249,7 +250,7 @@ def snippets(session): | 249 | 250 | ) | 250 | 251 |
| 251 | 252 | # 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) | 253 | 254 | session.install("google-cloud-storage", "-c", constraints_path) | 254 | 255 | session.install("grpcio", "-c", constraints_path) | 255 | 256 |
| @@ -336,7 +337,6 @@ def prerelease_deps(session): | 336 | 337 | "google-cloud-datacatalog", | 337 | 338 | "google-cloud-storage", | 338 | 339 | "google-cloud-testutils", | 339 | | - "mock", | 340 | 340 | "psutil", | 341 | 341 | "pytest", | 342 | 342 | "pytest-cov", | |
Collapse file Copy file name to clipboardExpand all lines: samples/desktopapp/user_credentials_test.py +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | # limitations under the License. | 14 | 14 |
| 15 | 15 | import os | | 16 | +import sys | 16 | 17 | from typing import Iterator, Union | | 18 | +from unittest import mock | 17 | 19 |
| 18 | 20 | import google.auth | 19 | | -import mock | 20 | 21 | import pytest | 21 | 22 |
| 22 | 23 | from .user_credentials import main # type: ignore | 23 | 24 |
| 24 | 25 | PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] | 25 | 26 |
| 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] | 27 | 34 |
| 28 | 35 |
| 29 | 36 | @pytest.fixture | |
Collapse file Copy file name to clipboardExpand all lines: samples/tests/conftest.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | import datetime | 16 | 16 | from typing import Iterator, List | | 17 | +from unittest import mock | 17 | 18 | import uuid | 18 | 19 |
| 19 | 20 | import google.auth | 20 | | -import mock | 21 | 21 | import pytest | 22 | 22 |
| 23 | 23 | from google.cloud import bigquery | |
Collapse file Copy file name to clipboardExpand all lines: testing/constraints-3.7.txt +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | # Then this file should have foo==1.14.0 | 8 | 8 | db-dtypes==0.3.0 | 9 | 9 | 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 | 14 | 18 | grpcio==1.47.0 | | 19 | +grpcio-status==1.47.0 | 15 | 20 | ipywidgets==7.7.1 | 16 | 21 | ipython==7.23.1 | 17 | 22 | ipykernel==6.0.0 | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/conftest.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | # See the License for the specific language governing permissions and | 13 | 13 | # limitations under the License. | 14 | 14 |
| 15 | | -import mock | | 15 | +from unittest import mock | | 16 | + | 16 | 17 | import pytest | 17 | 18 |
| 18 | 19 | from .helpers import make_client | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/helpers.py +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | # See the License for the specific language governing permissions and | 13 | 13 | # limitations under the License. | 14 | 14 |
| | 15 | +from unittest import mock | | 16 | + | | 17 | +import pytest | | 18 | + | 15 | 19 | import google.cloud.bigquery.client | 16 | 20 | import google.cloud.bigquery.dataset | 17 | | -import mock | 18 | | -import pytest | 19 | 21 |
| 20 | 22 |
| 21 | 23 | def make_connection(*responses): | 22 | 24 | import google.cloud.bigquery._http | 23 | | - import mock | 24 | 25 | from google.cloud.exceptions import NotFound | 25 | 26 |
| 26 | 27 | mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection) | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/job/test_base.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | import copy | 16 | 16 | import http | 17 | 17 | import unittest | | 18 | +from unittest import mock | 18 | 19 |
| 19 | 20 | from google.api_core import exceptions | 20 | 21 | import google.api_core.retry | 21 | 22 | from google.api_core.future import polling | 22 | | -import mock | 23 | 23 | import pytest | 24 | 24 |
| 25 | 25 | from ..helpers import make_connection | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/job/test_copy.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | # See the License for the specific language governing permissions and | 13 | 13 | # limitations under the License. | 14 | 14 |
| 15 | | -import mock | | 15 | +from unittest import mock | 16 | 16 |
| 17 | 17 | from ..helpers import make_connection | 18 | 18 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/job/test_extract.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 12 | 12 | # See the License for the specific language governing permissions and | 13 | 13 | # limitations under the License. | 14 | 14 |
| 15 | | -import mock | | 15 | +from unittest import mock | 16 | 16 |
| 17 | 17 | from ..helpers import make_connection | 18 | 18 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/job/test_load.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 13 | 13 | # limitations under the License. | 14 | 14 |
| 15 | 15 | import copy | 16 | | - | 17 | | -import mock | | 16 | +from unittest import mock | 18 | 17 |
| 19 | 18 | from ..helpers import make_connection | 20 | 19 |
| |
|