|
32 | 32 | from google.api_core import grpc_helpers_async |
33 | 33 | from google.api_core import operation_async # type: ignore |
34 | 34 | from google.api_core import operations_v1 |
| 35 | +from google.api_core import path_template |
35 | 36 | from google.auth import credentials as ga_credentials |
36 | 37 | from google.auth.exceptions import MutualTLSChannelError |
37 | 38 | from google.cloud.network_management_v1.services.reachability_service import ( |
@@ -2130,6 +2131,9 @@ def test_reachability_service_base_transport(): |
2130 | 2131 | with pytest.raises(NotImplementedError): |
2131 | 2132 | getattr(transport, method)(request=object()) |
2132 | 2133 |
|
| 2134 | + with pytest.raises(NotImplementedError): |
| 2135 | + transport.close() |
| 2136 | + |
2133 | 2137 | # Additionally, the LRO client (a property) should |
2134 | 2138 | # also raise NotImplementedError |
2135 | 2139 | with pytest.raises(NotImplementedError): |
@@ -2643,3 +2647,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): |
2643 | 2647 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, |
2644 | 2648 | ) |
2645 | 2649 | prep.assert_called_once_with(client_info) |
| 2650 | + |
| 2651 | + |
| 2652 | +@pytest.mark.asyncio |
| 2653 | +async def test_transport_close_async(): |
| 2654 | + client = ReachabilityServiceAsyncClient( |
| 2655 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 2656 | + ) |
| 2657 | + with mock.patch.object( |
| 2658 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 2659 | + ) as close: |
| 2660 | + async with client: |
| 2661 | + close.assert_not_called() |
| 2662 | + close.assert_called_once() |
| 2663 | + |
| 2664 | + |
| 2665 | +def test_transport_close(): |
| 2666 | + transports = { |
| 2667 | + "grpc": "_grpc_channel", |
| 2668 | + } |
| 2669 | + |
| 2670 | + for transport, close_name in transports.items(): |
| 2671 | + client = ReachabilityServiceClient( |
| 2672 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2673 | + ) |
| 2674 | + with mock.patch.object( |
| 2675 | + type(getattr(client.transport, close_name)), "close" |
| 2676 | + ) as close: |
| 2677 | + with client: |
| 2678 | + close.assert_not_called() |
| 2679 | + close.assert_called_once() |
| 2680 | + |
| 2681 | + |
| 2682 | +def test_client_ctx(): |
| 2683 | + transports = [ |
| 2684 | + "grpc", |
| 2685 | + ] |
| 2686 | + for transport in transports: |
| 2687 | + client = ReachabilityServiceClient( |
| 2688 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2689 | + ) |
| 2690 | + # Test client calls underlying transport. |
| 2691 | + with mock.patch.object(type(client.transport), "close") as close: |
| 2692 | + close.assert_not_called() |
| 2693 | + with client: |
| 2694 | + pass |
| 2695 | + close.assert_called() |
0 commit comments