diff --git a/packages/google-cloud-bigtable/.cross_sync/generate.py b/packages/google-cloud-bigtable/.cross_sync/generate.py index 5158d0f37338..8e6a214d8741 100644 --- a/packages/google-cloud-bigtable/.cross_sync/generate.py +++ b/packages/google-cloud-bigtable/.cross_sync/generate.py @@ -51,18 +51,55 @@ def render(self, with_formatter=True, save_to_disk: bool = True) -> str: Render the file to a string, and optionally save to disk Args: - with_formatter: whether to run the output through black before returning + with_formatter: whether to run the output through ruff before returning save_to_disk: whether to write the output to the file path """ full_str = self.header + ast.unparse(self.tree) if with_formatter: - import black # type: ignore - import autoflake # type: ignore - - full_str = black.format_str( - autoflake.fix_code(full_str, remove_all_unused_imports=True), - mode=black.FileMode(), - ) + import subprocess + import sys + + try: + # Run ruff check + result = subprocess.run( + [ + sys.executable, + "-m", + "ruff", + "check", + "--select", + "I,F401", + "--fix", + "--line-length=88", + "-", + ], + input=full_str, + text=True, + capture_output=True, + check=True, + ) + full_str = result.stdout + + # Run ruff format + result = subprocess.run( + [ + sys.executable, + "-m", + "ruff", + "format", + "--line-length=88", + "--config", + "format.skip-magic-trailing-comma=true", + "-", + ], + input=full_str, + text=True, + capture_output=True, + check=True, + ) + full_str = result.stdout + except subprocess.CalledProcessError as e: + print(f"ruff formatting failed: {e.stderr}") if save_to_disk: import os os.makedirs(os.path.dirname(self.output_path), exist_ok=True) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py index fad8e2469ecb..c1c508a526f2 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py @@ -16,9 +16,12 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + from typing import TYPE_CHECKING, Sequence + from google.api_core import exceptions as core_exceptions from google.api_core import retry as retries + import google.cloud.bigtable.data.exceptions as bt_exceptions import google.cloud.bigtable_v2.types.bigtable as types_pb from google.cloud.bigtable.data._cross_sync import CrossSync @@ -32,10 +35,10 @@ ) if TYPE_CHECKING: - from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable.data._sync_autogen.client import ( _DataApiTarget as TargetType, ) + from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable_v2.services.bigtable.client import ( BigtableClient as GapicClientType, ) diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py index 9ccde8b07761..a74374988161 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_read_rows.py @@ -17,9 +17,12 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + from typing import TYPE_CHECKING, Sequence + from google.api_core import retry as retries from google.api_core.retry import exponential_sleep_generator + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( _attempt_timeout_generator, diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py index 78ba129d98c5..93f2b44a6df6 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/_swappable_channel.py @@ -16,9 +16,10 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + from typing import Callable -from grpc import ChannelConnectivity -from grpc import Channel + +from grpc import Channel, ChannelConnectivity class _WrappedChannel(Channel): diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py index a5873ecc0931..d32e5d06b68a 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/client.py @@ -17,6 +17,7 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + import abc import concurrent.futures import os @@ -24,7 +25,8 @@ import time import warnings from functools import partial -from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Set, cast +from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, Sequence, Set, cast + import google.auth._default import google.auth.credentials from google.api_core import client_options as client_options_lib @@ -39,7 +41,8 @@ from google.cloud.environment_vars import BIGTABLE_EMULATOR from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper from google.protobuf.message import Message -from grpc import Channel +from grpc import Channel, insecure_channel, intercept_channel + from google.cloud.bigtable.client import _DEFAULT_BIGTABLE_EMULATOR_CLIENT from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( @@ -55,6 +58,13 @@ _WarmedInstanceKey, ) from google.cloud.bigtable.data._metrics import BigtableClientSideMetricsController +from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( + SwappableChannel as SwappableChannelType, +) +from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( + BigtableMetricsInterceptor as MetricsInterceptorType, +) +from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE from google.cloud.bigtable.data.exceptions import ( FailedQueryShardError, ShardedReadRowsExceptionGroup, @@ -78,6 +88,10 @@ RowFilterChain, StripValueTransformerFilter, ) +from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient +from google.cloud.bigtable_v2.services.bigtable.transports import ( + BigtableGrpcTransport as TransportType, +) from google.cloud.bigtable_v2.services.bigtable.transports.base import ( DEFAULT_CLIENT_INFO, ) @@ -88,19 +102,6 @@ ReadModifyWriteRowRequest, SampleRowKeysRequest, ) -from typing import Iterable -from grpc import insecure_channel, intercept_channel -from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( - SwappableChannel as SwappableChannelType, -) -from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( - BigtableMetricsInterceptor as MetricsInterceptorType, -) -from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE -from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient -from google.cloud.bigtable_v2.services.bigtable.transports import ( - BigtableGrpcTransport as TransportType, -) if TYPE_CHECKING: from google.cloud.bigtable.data._helpers import RowKeySamples, ShardedQuery @@ -297,8 +298,7 @@ def _ping_and_warm_instances( instance_key: if provided, only warm the instance associated with the key channel: grpc channel to warm. If none, warms `self.transport.grpc_channel` Returns: - list[BaseException | None]: sequence of results or exceptions from the ping requests - """ + list[BaseException | None]: sequence of results or exceptions from the ping requests""" channel = channel or self.transport.grpc_channel instance_list = ( [instance_key] if instance_key is not None else self._active_instances @@ -654,8 +654,7 @@ def execute_query( google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error google.cloud.bigtable.data.exceptions.ParameterTypeInferenceFailed: Raised if a parameter is passed without an explicit type, and the type cannot be infered - google.protobuf.message.DecodeError: raised if the deserialization of a PROTO/ENUM value fails. - """ + google.protobuf.message.DecodeError: raised if the deserialization of a PROTO/ENUM value fails.""" instance_name = self._gapic_client.instance_path(self.project, instance_id) converted_param_types = _to_param_types(parameters, parameter_types) prepare_request = { @@ -893,8 +892,7 @@ def read_rows_stream( google.api_core.exceptions.DeadlineExceeded: raised after operation timeout will be chained with a RetryExceptionGroup containing GoogleAPIError exceptions from any retries that failed - google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error - """ + google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error""" operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) @@ -944,8 +942,7 @@ def read_rows( google.api_core.exceptions.DeadlineExceeded: raised after operation timeout will be chained with a RetryExceptionGroup containing GoogleAPIError exceptions from any retries that failed - google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error - """ + google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error""" row_generator = self.read_rows_stream( query, operation_timeout=operation_timeout, @@ -987,8 +984,7 @@ def read_row( google.api_core.exceptions.DeadlineExceeded: raised after operation timeout will be chained with a RetryExceptionGroup containing GoogleAPIError exceptions from any retries that failed - google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error - """ + google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error""" if row_key is None: raise ValueError("row_key must be string or bytes") query = ReadRowsQuery(row_keys=row_key, row_filter=row_filter, limit=1) @@ -1121,8 +1117,7 @@ def row_exists( google.api_core.exceptions.DeadlineExceeded: raised after operation timeout will be chained with a RetryExceptionGroup containing GoogleAPIError exceptions from any retries that failed - google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error - """ + google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error""" if row_key is None: raise ValueError("row_key must be string or bytes") strip_filter = StripValueTransformerFilter(flag=True) @@ -1172,8 +1167,7 @@ def sample_row_keys( google.api_core.exceptions.DeadlineExceeded: raised after operation timeout will be chained with a RetryExceptionGroup containing GoogleAPIError exceptions from any retries that failed - google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error - """ + google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error""" operation_timeout, attempt_timeout = _get_timeouts( operation_timeout, attempt_timeout, self ) @@ -1236,8 +1230,7 @@ def mutations_batcher( batch_retryable_errors: a list of errors that will be retried if encountered. Defaults to the Table's default_mutate_rows_retryable_errors. Returns: - MutationsBatcher: a MutationsBatcher context manager that can batch requests - """ + MutationsBatcher: a MutationsBatcher context manager that can batch requests""" return CrossSync._Sync_Impl.MutationsBatcher( self, flush_interval=flush_interval, diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py index fc60c6e4e89b..4347cfa61bc1 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/metrics_interceptor.py @@ -15,15 +15,18 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + import time from functools import wraps from typing import Sequence + +from grpc import UnaryStreamClientInterceptor, UnaryUnaryClientInterceptor + from google.cloud.bigtable.data._metrics.data_model import ( ActiveOperationMetric, OperationState, OperationType, ) -from grpc import UnaryStreamClientInterceptor, UnaryUnaryClientInterceptor def _with_active_operation(func): diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py index 41952f73ba98..5be449a49d4a 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py @@ -16,11 +16,13 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + import atexit import concurrent.futures import warnings from collections import deque from typing import TYPE_CHECKING, Sequence, cast + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( TABLE_DEFAULT, @@ -37,10 +39,10 @@ ) if TYPE_CHECKING: - from google.cloud.bigtable.data.mutations import RowMutationEntry from google.cloud.bigtable.data._sync_autogen.client import ( _DataApiTarget as TargetType, ) + from google.cloud.bigtable.data.mutations import RowMutationEntry _MB_SIZE = 1024 * 1024 @@ -86,8 +88,7 @@ def _has_capacity(self, additional_count: int, additional_size: int) -> bool: additional_count: number of mutations in the pending entry additional_size: size of the pending entry Returns: - bool: True if there is capacity to send the pending entry, False otherwise - """ + bool: True if there is capacity to send the pending entry, False otherwise""" acceptable_size = max(self._max_mutation_bytes, additional_size) acceptable_count = max(self._max_mutation_count, additional_count) new_size = self._in_flight_mutation_bytes + additional_size @@ -440,8 +441,7 @@ def _wait_for_batch_results( list of Exceptions encountered by any of the tasks. Errors are expected to be FailedMutationEntryError, representing a failed mutation operation. If a task fails with a different exception, it will be included in the - output list. Successful tasks will not be represented in the output list. - """ + output list. Successful tasks will not be represented in the output list.""" if not tasks: return [] exceptions: list[Exception] = [] diff --git a/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py b/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py index d00457724eb5..3f2febdaa557 100644 --- a/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +++ b/packages/google-cloud-bigtable/google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py @@ -16,10 +16,13 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple + from google.api_core import retry as retries from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper from google.protobuf.message import Message + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._helpers import ( _attempt_timeout_generator, @@ -89,8 +92,7 @@ def __init__( for protobuf deserialization. Raises: None - :class:`ValueError ` as a safeguard if data is processed in an unexpected state - """ + :class:`ValueError ` as a safeguard if data is processed in an unexpected state""" self._table_name = None self._app_profile_id = app_profile_id self._client = client @@ -193,8 +195,7 @@ def _next_impl(self) -> CrossSync._Sync_Impl.Iterator[QueryResultRow]: def __next__(self) -> QueryResultRow: """Yields QueryResultRows representing the results of the query. - :raises: :class:`ValueError ` as a safeguard if data is processed in an unexpected state - """ + :raises: :class:`ValueError ` as a safeguard if data is processed in an unexpected state""" if self._is_closed: raise CrossSync._Sync_Impl.StopIteration return self._result_generator.__next__() @@ -242,8 +243,7 @@ def close(self) -> None: Called automatically by iterator - :raises: :class:`ValueError ` if called in an invalid state - """ + :raises: :class:`ValueError ` if called in an invalid state""" self._close_internal() def _close_internal(self) -> None: diff --git a/packages/google-cloud-bigtable/noxfile.py b/packages/google-cloud-bigtable/noxfile.py index b9883960a59e..279fb9d578eb 100644 --- a/packages/google-cloud-bigtable/noxfile.py +++ b/packages/google-cloud-bigtable/noxfile.py @@ -43,8 +43,7 @@ "pytest", "pytest-cov", "pytest-asyncio", - BLACK_VERSION, - "autoflake", + RUFF_VERSION, ] UNIT_TEST_EXTERNAL_DEPENDENCIES: List[str] = [] UNIT_TEST_LOCAL_DEPENDENCIES: List[str] = [] @@ -553,8 +552,7 @@ def generate_sync(session): """ Re-generate sync files for the library from CrossSync-annotated async source """ - session.install(BLACK_VERSION) - session.install("autoflake") + session.install(RUFF_VERSION) session.run("python", ".cross_sync/generate.py", ".") diff --git a/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py b/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py index 16b8382fca41..b2864db94b21 100644 --- a/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py +++ b/packages/google-cloud-bigtable/test_proxy/handlers/client_handler_data_sync_autogen.py @@ -17,11 +17,14 @@ """ This module contains the client handler process for proxy_server.py. """ + import os + +from client_handler_data_async import error_safe from google.cloud.environment_vars import BIGTABLE_EMULATOR -from google.cloud.bigtable.data._cross_sync import CrossSync from helpers import sql_encoding_helpers -from client_handler_data_async import error_safe + +from google.cloud.bigtable.data._cross_sync import CrossSync class TestProxyClientHandler: @@ -41,7 +44,7 @@ def __init__( instance_id=None, app_profile_id=None, per_operation_timeout=None, - **kwargs + **kwargs, ): self.closed = False os.environ[BIGTABLE_EMULATOR] = data_target @@ -140,14 +143,16 @@ async def CheckAndMutateRow(self, request, **kwargs): predicate_filter, true_case_mutations=true_mutations, false_case_mutations=false_mutations, - **kwargs + **kwargs, ) return result @error_safe async def ReadModifyWriteRow(self, request, **kwargs): - from google.cloud.bigtable.data.read_modify_write_rules import IncrementRule - from google.cloud.bigtable.data.read_modify_write_rules import AppendValueRule + from google.cloud.bigtable.data.read_modify_write_rules import ( + AppendValueRule, + IncrementRule, + ) table_id = request["table_name"].split("/")[-1] app_profile_id = self.app_profile_id or request.get("app_profile_id", None) diff --git a/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py b/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py index d791da75ab13..ae9d0206d933 100644 --- a/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py +++ b/packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py @@ -18,11 +18,15 @@ import os from datetime import datetime, timedelta from typing import Tuple + import pytest +from google.api_core import operation as api_core_operation from google.cloud.environment_vars import BIGTABLE_EMULATOR + from google.cloud import bigtable_admin_v2 as admin_v2 from google.cloud.bigtable.data import mutations, read_rows_query from google.cloud.bigtable.data._cross_sync import CrossSync + from .conftest import ( BACKUP_PREFIX, DEFAULT_CLUSTER_LOCATIONS, @@ -38,7 +42,6 @@ TEST_TABLE_NAME, generate_unique_suffix, ) -from google.api_core import operation as api_core_operation if os.getenv(BIGTABLE_EMULATOR): pytest.skip( @@ -101,8 +104,7 @@ def create_instance( """Creates a new Bigtable instance with the specified project_id, storage type, and cluster locations. After creating the Bigtable instance, it will create a test table and populate it with dummy data. - This is not defined as a fixture because the different system tests need different kinds of instances. - """ + This is not defined as a fixture because the different system tests need different kinds of instances.""" clusters = {} instance_id = generate_unique_suffix(INSTANCE_PREFIX) for idx, location in enumerate(cluster_locations): diff --git a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py index 396f7b1a0605..a324c514be28 100644 --- a/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py +++ b/packages/google-cloud-bigtable/tests/system/data/test_system_autogen.py @@ -18,19 +18,22 @@ import datetime import os import uuid + import pytest from google.api_core import retry from google.api_core.exceptions import ClientError, PermissionDenied from google.cloud.environment_vars import BIGTABLE_EMULATOR from google.type import date_pb2 + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.execute_query.metadata import SqlType from google.cloud.bigtable.data.read_modify_write_rules import _MAX_INCREMENT_VALUE -from . import TEST_AGGREGATE_FAMILY, TEST_FAMILY, TEST_FAMILY_2 from google.cloud.bigtable_v2.services.bigtable.transports.grpc import ( _LoggingClientInterceptor as GapicInterceptor, ) +from . import TEST_AGGREGATE_FAMILY, TEST_FAMILY, TEST_FAMILY_2 + TARGETS = ["table"] if not os.environ.get(BIGTABLE_EMULATOR): TARGETS.append("authorized_view") diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py index a9c841399098..3bce82f1e50f 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__mutate_rows.py @@ -18,6 +18,7 @@ import pytest from google.api_core.exceptions import DeadlineExceeded, Forbidden from google.rpc import status_pb2 + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.mutations import DeleteAllFromRow, RowMutationEntry from google.cloud.bigtable_v2.types import MutateRowsResponse @@ -73,6 +74,7 @@ def _make_mock_gapic(self, mutation_list, error_dict=None): def test_ctor(self): """test that constructor sets all the attributes correctly""" from google.api_core.exceptions import Aborted, DeadlineExceeded + from google.cloud.bigtable.data._async._mutate_rows import _EntryWithProto from google.cloud.bigtable.data.exceptions import _MutateRowsIncomplete @@ -223,6 +225,7 @@ def test_mutate_rows_exception_retryable_eventually_pass(self, exc_type): def test_mutate_rows_incomplete_ignored(self): """MutateRowsIncomplete exceptions should not be added to error list""" from google.api_core.exceptions import DeadlineExceeded + from google.cloud.bigtable.data.exceptions import ( MutationsExceptionGroup, _MutateRowsIncomplete, diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py index eb0343dd4a20..f16a523e862d 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__read_rows.py @@ -16,6 +16,7 @@ # This file is automatically generated by CrossSync. Do not edit manually. import pytest + from google.cloud.bigtable.data._cross_sync import CrossSync try: diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py index 04f3f61c8d86..25429bdc8a28 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test__swappable_channel.py @@ -22,6 +22,7 @@ import mock import pytest from grpc import ChannelConnectivity + from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( SwappableChannel as TargetType, ) diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py index 0d5e47b1072b..b18ee6fdd8b7 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_client.py @@ -15,16 +15,23 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + import asyncio import re + import grpc import mock import pytest -from google.api_core import client_options +from google.api_core import client_options, grpc_helpers from google.api_core import exceptions as core_exceptions from google.auth.credentials import AnonymousCredentials + from google.cloud.bigtable.data import TABLE_DEFAULT, mutations from google.cloud.bigtable.data._cross_sync import CrossSync +from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel +from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( + BigtableMetricsInterceptor, +) from google.cloud.bigtable.data.exceptions import InvalidChunk, _MutateRowsIncomplete from google.cloud.bigtable.data.mutations import DeleteAllFromRow from google.cloud.bigtable.data.read_modify_write_rules import ( @@ -45,11 +52,6 @@ str_type, str_val, ) -from google.api_core import grpc_helpers -from google.cloud.bigtable.data._sync_autogen._swappable_channel import SwappableChannel -from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( - BigtableMetricsInterceptor, -) CrossSync._Sync_Impl.add_mapping("grpc_helpers", grpc_helpers) CrossSync._Sync_Impl.add_mapping("SwappableChannel", SwappableChannel) @@ -749,6 +751,7 @@ def test_api_surface_arg_passthrough(self, method): def test_api_surface_context_manager(self, method): """get_table and get_authorized_view should work as context managers""" from functools import partial + from google.cloud.bigtable.data._helpers import _WarmedInstanceKey expected_table_id = "table-id" @@ -1886,6 +1889,7 @@ def test_read_rows_sharded_expirary(self): """If the operation times out before all shards complete, should raise a ShardedReadRowsExceptionGroup""" from google.api_core.exceptions import DeadlineExceeded + from google.cloud.bigtable.data._helpers import _CONCURRENCY_LIMIT from google.cloud.bigtable.data.exceptions import ShardedReadRowsExceptionGroup @@ -1921,6 +1925,7 @@ def test_read_rows_sharded_negative_batch_timeout(self): They should raise DeadlineExceeded errors""" from google.api_core.exceptions import DeadlineExceeded + from google.cloud.bigtable.data._helpers import _CONCURRENCY_LIMIT from google.cloud.bigtable.data.exceptions import ShardedReadRowsExceptionGroup @@ -2042,6 +2047,7 @@ def test_sample_row_keys_gapic_params(self): def test_sample_row_keys_retryable_errors(self, retryable_exception): """retryable errors should be retried until timeout""" from google.api_core.exceptions import DeadlineExceeded + from google.cloud.bigtable.data.exceptions import RetryExceptionGroup with self._make_client() as client: @@ -2142,6 +2148,7 @@ def test_mutate_row(self, mutation_arg): ) def test_mutate_row_retryable_errors(self, retryable_exception): from google.api_core.exceptions import DeadlineExceeded + from google.cloud.bigtable.data.exceptions import RetryExceptionGroup with self._make_client(project="project") as client: @@ -2220,6 +2227,7 @@ def _make_client(self, *args, **kwargs): def _mock_response(self, response_list): from google.rpc import status_pb2 + from google.cloud.bigtable_v2.types import MutateRowsResponse statuses = [] @@ -2491,6 +2499,7 @@ def test_bulk_mutate_error_index(self): FailedPrecondition, ServiceUnavailable, ) + from google.cloud.bigtable.data.exceptions import ( FailedMutationEntryError, MutationsExceptionGroup, diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py index e89108e12bc6..20d7a62646dd 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_metrics_interceptor.py @@ -17,6 +17,7 @@ import pytest from grpc import ClientCallDetails, RpcError + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data._metrics.data_model import ( ActiveOperationMetric, diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py index 9f5bec2efb82..f6568448ff8c 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_mutations_batcher.py @@ -17,10 +17,12 @@ import asyncio import time + import google.api_core.exceptions as core_exceptions import google.api_core.retry import mock import pytest + from google.cloud.bigtable.data import TABLE_DEFAULT from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.exceptions import _MutateRowsIncomplete @@ -769,6 +771,7 @@ def gen(x): def _mock_gapic_return(self, num=5): from google.rpc import status_pb2 + from google.cloud.bigtable_v2.types import MutateRowsResponse def gen(num): @@ -984,8 +987,7 @@ def test__add_exceptions(self, limit, in_e, start_e, end_e): - limit: the _exception_list_limit representing the max size of either list - in_e: size of list of exceptions to send to _add_exceptions - start_e: a tuple of ints representing the initial sizes of _oldest_exceptions and _newest_exceptions - - end_e: a tuple of ints representing the expected sizes of _oldest_exceptions and _newest_exceptions - """ + - end_e: a tuple of ints representing the expected sizes of _oldest_exceptions and _newest_exceptions""" from collections import deque input_list = [RuntimeError(f"mock {i}") for i in range(in_e)] diff --git a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py index 0950576645e8..29332e712d35 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py +++ b/packages/google-cloud-bigtable/tests/unit/data/_sync_autogen/test_read_rows_acceptance.py @@ -15,15 +15,19 @@ # This file is automatically generated by CrossSync. Do not edit manually. from __future__ import annotations + import os import warnings from itertools import zip_longest + import mock import pytest + from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.exceptions import InvalidChunk from google.cloud.bigtable.data.row import Row from google.cloud.bigtable_v2 import ReadRowsResponse + from ...v2_client.test_row_merger import ReadRowsTest, TestFile diff --git a/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py b/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py index 25666e8b9d3b..7c3efce32126 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py +++ b/packages/google-cloud-bigtable/tests/unit/data/execute_query/_sync_autogen/test_query_iterator.py @@ -17,12 +17,15 @@ import concurrent.futures import gc + import pytest + from google.cloud.bigtable.data import exceptions from google.cloud.bigtable.data._cross_sync import CrossSync from google.cloud.bigtable.data.execute_query.metadata import ( _pb_metadata_to_metadata_types, ) + from ..sql_helpers import chunked_responses, column, int64_type, int_val, metadata try: diff --git a/packages/google-cloud-bigtable/tests/unit/data/test_sync_up_to_date.py b/packages/google-cloud-bigtable/tests/unit/data/test_sync_up_to_date.py index 4efaa4e903df..ec31139b7e56 100644 --- a/packages/google-cloud-bigtable/tests/unit/data/test_sync_up_to_date.py +++ b/packages/google-cloud-bigtable/tests/unit/data/test_sync_up_to_date.py @@ -62,7 +62,9 @@ def test_sync_up_to_date(sync_file): path = sync_file.output_path new_render = sync_file.render(with_formatter=True, save_to_disk=False) found_render = CrossSyncOutputFile( - output_path="", ast_tree=ast.parse(open(path).read()), header=sync_file.header + output_path="dummy.py", + ast_tree=ast.parse(open(path).read()), + header=sync_file.header, ).render(with_formatter=True, save_to_disk=False) # compare by content diff = unified_diff(found_render.splitlines(), new_render.splitlines(), lineterm="")