@@ -361,7 +361,7 @@ async def test_handle_grpc_failure(self):
361361 mock_error_message = _MOCK_FAILURE_VALUE
362362
363363 class MockRpcErrorResponse (grpc .RpcError ):
364- def code (self ):
364+ async def code (self ):
365365 return grpc .StatusCode .INVALID_ARGUMENT
366366
367367 async def trailing_metadata (self ):
@@ -373,13 +373,16 @@ def exception(self):
373373 interceptor = self ._create_test_interceptor ()
374374
375375 with self .assertRaises (GoogleAdsException ):
376- await interceptor ._handle_grpc_failure_async (MockRpcErrorResponse ())
376+ error_response = MockRpcErrorResponse ()
377+ await interceptor ._handle_grpc_failure_async (
378+ error_response , error_response
379+ )
377380
378381 async def test_handle_grpc_failure_retryable (self ):
379382 """Raises retryable exceptions as-is."""
380383
381384 class MockRpcErrorResponse (grpc .RpcError ):
382- def code (self ):
385+ async def code (self ):
383386 return grpc .StatusCode .INTERNAL
384387
385388 def exception (self ):
@@ -388,13 +391,16 @@ def exception(self):
388391 interceptor = self ._create_test_interceptor ()
389392
390393 with self .assertRaises (MockRpcErrorResponse ):
391- await interceptor ._handle_grpc_failure_async (MockRpcErrorResponse ())
394+ error_response = MockRpcErrorResponse ()
395+ await interceptor ._handle_grpc_failure_async (
396+ error_response , error_response
397+ )
392398
393399 async def test_handle_grpc_failure_not_google_ads_failure (self ):
394400 """Raises as-is non-retryable non-GoogleAdsFailure exceptions."""
395401
396402 class MockRpcErrorResponse (grpc .RpcError ):
397- def code (self ):
403+ async def code (self ):
398404 return grpc .StatusCode .INVALID_ARGUMENT
399405
400406 async def trailing_metadata (self ):
@@ -406,7 +412,10 @@ def exception(self):
406412 interceptor = self ._create_test_interceptor ()
407413
408414 with self .assertRaises (MockRpcErrorResponse ):
409- await interceptor ._handle_grpc_failure_async (MockRpcErrorResponse ())
415+ error_response = MockRpcErrorResponse ()
416+ await interceptor ._handle_grpc_failure_async (
417+ error_response , error_response
418+ )
410419
411420 async def test_intercept_unary_unary_response_is_exception (self ):
412421 """If response.exception() is not None exception is handled."""
@@ -439,7 +448,7 @@ async def mock_continuation(client_call_details, request):
439448 except grpc .RpcError :
440449 pass
441450
442- mock_handle .assert_called_once_with (mock_call )
451+ mock_handle .assert_called_once_with (mock_call , mock_exception )
443452
444453 async def test_intercept_unary_stream_response_is_exception (self ):
445454 """Ensure errors raised from response iteration are handled/wrapped."""
@@ -470,21 +479,15 @@ async def mock_continuation(client_call_details, request):
470479 mock_continuation , mock_client_call_details , mock_request
471480 )
472481
473- # Ensure the returned value is a wrapped response object.
474482 self .assertIsInstance (response , _AsyncUnaryStreamCallWrapper )
475483
476- # Initiate an iteration of the wrapped response object
477484 try :
478485 async for _ in response :
479- # This loop body should not be entered because the exception
480- # is raised on the first attempt to get an item.
481486 pass
482487 except grpc .RpcError :
483488 pass
484489
485- # Check that the error handler method on the interceptor instance
486- # was called as a result of the iteration.
487- mock_handle .assert_called_once_with (mock_call )
490+ mock_handle .assert_called_once_with (mock_call , mock_exception )
488491
489492 async def test_intercept_unary_unary_response_is_successful (self ):
490493 """If response.exception() is None response is returned."""
@@ -625,7 +628,9 @@ async def mock_continuation(client_call_details, request):
625628 found = True
626629 break # We only need the first item
627630
628- self .assertTrue (found , "Iterator should have yielded at least one message" )
631+ self .assertTrue (
632+ found , "Iterator should have yielded at least one message"
633+ )
629634 self .assertIsInstance (message , proto .Message )
630635
631636 async def test_intercept_unary_stream_protobuf_proto (self ):
@@ -661,5 +666,7 @@ async def mock_continuation(client_call_details, request):
661666 found = True
662667 break # We only need the first item
663668
664- self .assertTrue (found , "Iterator should have yielded at least one message" )
669+ self .assertTrue (
670+ found , "Iterator should have yielded at least one message"
671+ )
665672 self .assertIsInstance (message , ProtobufMessageType )
0 commit comments