Skip to content
Merged
8 changes: 4 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def default(session, install_extras=True):

# Install all test dependencies, then install local packages in-place.
session.install(
"mock",
"pytest",
"google-cloud-testutils",
"pytest-cov",
Expand All @@ -89,6 +88,8 @@ def default(session, install_extras=True):
install_target = "."
session.install("-e", install_target, "-c", constraints_path)

session.run("python", "-m", "pip", "freeze")

# Run py.test against the unit tests.
session.run(
"py.test",
Expand Down Expand Up @@ -176,7 +177,7 @@ def system(session):

# Install all test dependencies, then install local packages in place.
session.install(
"mock", "pytest", "psutil", "google-cloud-testutils", "-c", constraints_path
"pytest", "psutil", "google-cloud-testutils", "-c", constraints_path
)
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "") == "true":
# mTLS test requires pyopenssl and latest google-cloud-storage
Expand Down Expand Up @@ -249,7 +250,7 @@ def snippets(session):
)

# Install all test dependencies, then install local packages in place.
session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path)
session.install("pytest", "google-cloud-testutils", "-c", constraints_path)
session.install("google-cloud-storage", "-c", constraints_path)
session.install("grpcio", "-c", constraints_path)

Expand Down Expand Up @@ -336,7 +337,6 @@ def prerelease_deps(session):
"google-cloud-datacatalog",
"google-cloud-storage",
"google-cloud-testutils",
"mock",
"psutil",
"pytest",
"pytest-cov",
Expand Down
11 changes: 9 additions & 2 deletions samples/desktopapp/user_credentials_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@
# limitations under the License.

import os
import sys
from typing import Iterator, Union
from unittest import mock

import google.auth
import mock
import pytest

from .user_credentials import main # type: ignore

PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]

MockType = Union[mock.mock.MagicMock, mock.mock.AsyncMock]

if sys.version_info >= (3, 8):
# Python 3.8+ has an AsyncMock attribute in unittest.mock, but 3.7 does not
MockType = Union[mock.MagicMock, mock.AsyncMock]
else:
# Other definitions and imports
MockType = Union[mock.MagicMock]


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion samples/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

import datetime
from typing import Iterator, List
from unittest import mock
import uuid

import google.auth
import mock
import pytest

from google.cloud import bigquery
Expand Down
13 changes: 9 additions & 4 deletions testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
# Then this file should have foo==1.14.0
db-dtypes==0.3.0
geopandas==0.9.0
google-api-core==1.31.5
google-cloud-bigquery-storage==2.6.0
google-cloud-core==1.6.0
google-resumable-media==0.6.0
google-api-core==2.17.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we updated these without updating the corresponding minimum versions in setup.py. I'll try to revert as much as I can. Do we know why we needed to upgrade these?

google-auth==2.28.1
google-cloud-bigquery-storage==2.24.0
google-cloud-core==2.4.1
google-cloud-testutils==1.4.0
google-crc32c==1.5.0
google-resumable-media==2.7.0
googleapis-common-protos==1.62.0
grpcio==1.47.0
grpcio-status==1.47.0
ipywidgets==7.7.1
ipython==7.23.1
ipykernel==6.0.0
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

import pytest

from .helpers import make_client
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

import pytest

import google.cloud.bigquery.client
import google.cloud.bigquery.dataset
import mock
import pytest


def make_connection(*responses):
import google.cloud.bigquery._http
import mock
from google.cloud.exceptions import NotFound

mock_conn = mock.create_autospec(google.cloud.bigquery._http.Connection)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/job/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import copy
import http
import unittest
from unittest import mock

from google.api_core import exceptions
import google.api_core.retry
from google.api_core.future import polling
import mock
import pytest

from ..helpers import make_connection
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/job/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

from ..helpers import make_connection

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/job/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
from unittest import mock

from ..helpers import make_connection

Expand Down
3 changes: 1 addition & 2 deletions tests/unit/job/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

import copy

import mock
from unittest import mock

from ..helpers import make_connection

Expand Down
16 changes: 8 additions & 8 deletions tests/unit/job/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import http
import textwrap
import types
from unittest import mock

import freezegun
from google.api_core import exceptions
import google.api_core.retry
import mock
import requests

from google.cloud.bigquery.client import _LIST_ROWS_FROM_QUERY_RESULTS_FIELDS
Expand Down Expand Up @@ -382,11 +382,11 @@ def test__done_or_raise_w_timeout(self):
job._done_or_raise(timeout=42)

fake_get_results.assert_called_once()
call_args = fake_get_results.call_args
self.assertEqual(call_args.kwargs.get("timeout"), 42)
call_args = fake_get_results.call_args[0][1]
self.assertEqual(call_args.timeout, 600.0)

call_args = fake_reload.call_args
self.assertEqual(call_args.kwargs.get("timeout"), 42)
call_args = fake_reload.call_args[1]
self.assertEqual(call_args["timeout"], 42)

def test__done_or_raise_w_timeout_and_longer_internal_api_timeout(self):
client = _make_client(project=self.PROJECT)
Expand All @@ -404,11 +404,11 @@ def test__done_or_raise_w_timeout_and_longer_internal_api_timeout(self):
expected_timeout = 5.5

fake_get_results.assert_called_once()
call_args = fake_get_results.call_args
self.assertAlmostEqual(call_args.kwargs.get("timeout"), expected_timeout)
call_args = fake_get_results.call_args[0][1]
self.assertAlmostEqual(call_args.timeout, 600.0)

call_args = fake_reload.call_args
self.assertAlmostEqual(call_args.kwargs.get("timeout"), expected_timeout)
self.assertAlmostEqual(call_args[1].get("timeout"), expected_timeout)

def test__done_or_raise_w_query_results_error_reload_ok(self):
client = _make_client(project=self.PROJECT)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/job/test_query_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import concurrent.futures
import copy
import json
from unittest import mock

import mock
import pytest


Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
import datetime
import decimal
import json
import unittest
import os
import mock
import pytest
import packaging
import unittest
from unittest import mock

import google.api_core


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test__http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import unittest
from unittest import mock

import mock
import requests


Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test__pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import functools
import operator
import queue
from unittest import mock
import warnings

try:
import importlib.metadata as metadata
except ImportError:
import importlib_metadata as metadata

import mock

try:
import pandas
import pandas.api.types
Expand Down Expand Up @@ -1200,7 +1199,7 @@ def test_dataframe_to_parquet_compression_method(module_under_test):

call_args = fake_write_table.call_args
assert call_args is not None
assert call_args.kwargs.get("compression") == "ZSTD"
assert call_args[1].get("compression") == "ZSTD"


@pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
Expand Down Expand Up @@ -1635,7 +1634,7 @@ def test_dataframe_to_parquet_dict_sequence_schema(module_under_test):
schema.SchemaField("field01", "STRING", mode="REQUIRED"),
schema.SchemaField("field02", "BOOL", mode="NULLABLE"),
]
schema_arg = fake_to_arrow.call_args.args[1]
schema_arg = fake_to_arrow.call_args[0][1]
assert schema_arg == expected_schema_arg


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test__versions_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
from unittest import mock

import mock
import pytest

try:
import pyarrow # type: ignore
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import json
import operator
import unittest
from unittest import mock
import warnings

import mock
import requests
import packaging
import pytest
Expand Down Expand Up @@ -8733,9 +8733,9 @@ def test_load_table_from_dataframe_w_schema_arrow_custom_compression(self):
parquet_compression="LZ4",
)

call_args = fake_to_parquet.call_args
call_args = fake_to_parquet.call_args[1]
assert call_args is not None
assert call_args.kwargs.get("parquet_compression") == "LZ4"
assert call_args.get("parquet_compression") == "LZ4"

@unittest.skipIf(pandas is None, "Requires `pandas`")
@unittest.skipIf(pyarrow is None, "Requires `pyarrow`")
Expand Down Expand Up @@ -9498,12 +9498,11 @@ def test__do_resumable_upload_custom_project(self):
timeout=mock.ANY,
)

# Check the project ID used in the call to initiate resumable upload.
initiation_url = next(
(
call.args[1]
call[0][1]
for call in transport.request.call_args_list
if call.args[0] == "POST" and "uploadType=resumable" in call.args[1]
if call[0][0] == "POST" and "uploadType=resumable" in call[0][1]
),
None,
) # pragma: NO COVER
Expand All @@ -9525,7 +9524,7 @@ def test__do_resumable_upload_custom_timeout(self):

# The timeout should be applied to all underlying calls.
for call_args in transport.request.call_args_list:
assert call_args.kwargs.get("timeout") == 3.14
assert call_args[1].get("timeout") == 3.14

def test__do_multipart_upload(self):
transport = self._make_transport([self._make_response(http.client.OK)])
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

from google.cloud.bigquery.dataset import Dataset, DatasetReference
from .helpers import make_connection, dataset_polymorphic, make_client
import google.cloud.bigquery.dataset
from google.cloud.bigquery.retry import DEFAULT_TIMEOUT
import mock
import pytest


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import unittest
from unittest import mock

import mock
from google.cloud.bigquery.routine.routine import Routine, RoutineReference
import pytest
from google.cloud.bigquery.dataset import (
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_dbapi_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

import gc
import unittest

import mock
from unittest import mock

try:
from google.cloud import bigquery_storage
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_dbapi_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.

import functools
import mock
import operator as op
import unittest
from unittest import mock

import pytest

Expand Down
Loading