Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit b6eac6c

Browse files
committed
fixed lint
1 parent 4871abd commit b6eac6c

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

google/cloud/bigtable/data/_async/metrics_interceptor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ def wrapper(self, continuation, client_call_details, request):
5454
operation: "ActiveOperationMetric" = self.operation_map.get(key)
5555
if operation:
5656
# start a new attempt if not started
57-
if operation.state == OperationState.CREATED or operation.state == OperationState.BETWEEN_ATTEMPTS:
57+
if (
58+
operation.state == OperationState.CREATED
59+
or operation.state == OperationState.BETWEEN_ATTEMPTS
60+
):
5861
operation.start_attempt()
5962
# wrap continuation in logic to process the operation
6063
return func(self, operation, continuation, client_call_details, request)
@@ -85,6 +88,7 @@ async def _get_metadata(source):
8588
# ignore errors while fetching metadata
8689
return None
8790

91+
8892
@CrossSync.convert_class(sync_name="BigtableMetricsInterceptor")
8993
class AsyncBigtableMetricsInterceptor(
9094
UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor, MetricsHandler
@@ -167,4 +171,4 @@ async def response_wrapper(call):
167171
except Exception as rpc_error:
168172
# handle errors while intializing stream
169173
_end_attempt(operation, rpc_error, await _get_metadata(rpc_error))
170-
raise rpc_error
174+
raise rpc_error

tests/unit/data/_async/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,9 @@ def _make_one(
11601160
@CrossSync.pytest
11611161
async def test_ctor(self):
11621162
from google.cloud.bigtable.data._helpers import _WarmedInstanceKey
1163-
from google.cloud.bigtable.data._metrics import BigtableClientSideMetricsController
1163+
from google.cloud.bigtable.data._metrics import (
1164+
BigtableClientSideMetricsController,
1165+
)
11641166

11651167
expected_table_id = "table-id"
11661168
expected_instance_id = "instance-id"
@@ -1493,7 +1495,9 @@ def _make_one(
14931495
@CrossSync.pytest
14941496
async def test_ctor(self):
14951497
from google.cloud.bigtable.data._helpers import _WarmedInstanceKey
1496-
from google.cloud.bigtable.data._metrics import BigtableClientSideMetricsController
1498+
from google.cloud.bigtable.data._metrics import (
1499+
BigtableClientSideMetricsController,
1500+
)
14971501

14981502
expected_table_id = "table-id"
14991503
expected_instance_id = "instance-id"

tests/unit/data/_async/test_metrics_interceptor.py

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

1515
import pytest
16-
import asyncio
1716
from grpc import RpcError
1817

1918
from google.cloud.bigtable.data._metrics.data_model import OperationState
@@ -26,32 +25,43 @@
2625
import mock # type: ignore
2726

2827
if CrossSync.is_async:
29-
from google.cloud.bigtable.data._async.metrics_interceptor import AsyncBigtableMetricsInterceptor
28+
from google.cloud.bigtable.data._async.metrics_interceptor import (
29+
AsyncBigtableMetricsInterceptor,
30+
)
3031
else:
31-
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import BigtableMetricsInterceptor
32+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import ( # noqa: F401
33+
BigtableMetricsInterceptor,
34+
)
3235

3336

3437
__CROSS_SYNC_OUTPUT__ = "tests.unit.data._sync_autogen.test_metrics_interceptor"
3538

39+
3640
@CrossSync.convert(replace_symbols={"__aiter__": "__iter__"})
3741
def _make_mock_stream_call(values, exc=None):
3842
"""
3943
Create a mock call object that can be used for streaming calls
4044
"""
4145
call = CrossSync.Mock()
46+
4247
async def gen():
4348
for val in values:
4449
yield val
4550
if exc:
4651
raise exc
52+
4753
call.__aiter__ = mock.Mock(return_value=gen())
4854
return call
4955

5056

5157
@CrossSync.convert_class(sync_name="TestMetricsInterceptor")
5258
class TestMetricsInterceptorAsync:
5359
@staticmethod
54-
@CrossSync.convert(replace_symbols={"AsyncBigtableMetricsInterceptor": "BigtableMetricsInterceptor"})
60+
@CrossSync.convert(
61+
replace_symbols={
62+
"AsyncBigtableMetricsInterceptor": "BigtableMetricsInterceptor"
63+
}
64+
)
5565
def _get_target_class():
5666
return AsyncBigtableMetricsInterceptor
5767

@@ -170,7 +180,6 @@ async def test_unary_unary_interceptor_failure(self):
170180
exc.trailing_metadata = CrossSync.Mock(return_value=[("a", "b")])
171181
exc.initial_metadata = CrossSync.Mock(return_value=[("c", "d")])
172182
continuation = CrossSync.Mock(side_effect=exc)
173-
call = continuation.return_value
174183
details = mock.Mock()
175184
details.metadata = [(OPERATION_INTERCEPTOR_METADATA_KEY, op.uuid)]
176185
request = mock.Mock()
@@ -235,7 +244,6 @@ async def test_unary_unary_interceptor_failure_generic(self):
235244
op.add_response_metadata.assert_not_called()
236245
op.end_attempt_with_status.assert_called_once_with(exc)
237246

238-
239247
@CrossSync.pytest
240248
async def test_unary_stream_interceptor_op_not_found(self):
241249
"""Test that interceptor calls continuation if op is not found"""
@@ -446,4 +454,4 @@ async def test_unary_stream_interceptor_start_operation(self, initial_state):
446454
details.metadata = [(OPERATION_INTERCEPTOR_METADATA_KEY, op.uuid)]
447455
request = mock.Mock()
448456
await instance.intercept_unary_stream(continuation, details, request)
449-
op.start_attempt.assert_called_once()
457+
op.start_attempt.assert_called_once()

tests/unit/data/_sync_autogen/test_metrics_interceptor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def test_unary_unary_interceptor_failure(self):
152152
exc.trailing_metadata = CrossSync._Sync_Impl.Mock(return_value=[("a", "b")])
153153
exc.initial_metadata = CrossSync._Sync_Impl.Mock(return_value=[("c", "d")])
154154
continuation = CrossSync._Sync_Impl.Mock(side_effect=exc)
155-
call = continuation.return_value
156155
details = mock.Mock()
157156
details.metadata = [(OPERATION_INTERCEPTOR_METADATA_KEY, op.uuid)]
158157
request = mock.Mock()

0 commit comments

Comments
 (0)