1313# limitations under the License.
1414
1515import pytest
16- import asyncio
1716from grpc import RpcError
1817
1918from google .cloud .bigtable .data ._metrics .data_model import OperationState
2625 import mock # type: ignore
2726
2827if 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+ )
3031else :
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__" })
3741def _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" )
5258class 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 ()
0 commit comments