|
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.shell_v1.services.cloud_shell_service import (
|
@@ -1414,6 +1415,9 @@ def test_cloud_shell_service_base_transport():
|
1414 | 1415 | with pytest.raises(NotImplementedError):
|
1415 | 1416 | getattr(transport, method)(request=object())
|
1416 | 1417 |
|
| 1418 | + with pytest.raises(NotImplementedError): |
| 1419 | + transport.close() |
| 1420 | + |
1417 | 1421 | # Additionally, the LRO client (a property) should
|
1418 | 1422 | # also raise NotImplementedError
|
1419 | 1423 | with pytest.raises(NotImplementedError):
|
@@ -1927,3 +1931,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
1927 | 1931 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
1928 | 1932 | )
|
1929 | 1933 | prep.assert_called_once_with(client_info)
|
| 1934 | + |
| 1935 | + |
| 1936 | +@pytest.mark.asyncio |
| 1937 | +async def test_transport_close_async(): |
| 1938 | + client = CloudShellServiceAsyncClient( |
| 1939 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 1940 | + ) |
| 1941 | + with mock.patch.object( |
| 1942 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 1943 | + ) as close: |
| 1944 | + async with client: |
| 1945 | + close.assert_not_called() |
| 1946 | + close.assert_called_once() |
| 1947 | + |
| 1948 | + |
| 1949 | +def test_transport_close(): |
| 1950 | + transports = { |
| 1951 | + "grpc": "_grpc_channel", |
| 1952 | + } |
| 1953 | + |
| 1954 | + for transport, close_name in transports.items(): |
| 1955 | + client = CloudShellServiceClient( |
| 1956 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1957 | + ) |
| 1958 | + with mock.patch.object( |
| 1959 | + type(getattr(client.transport, close_name)), "close" |
| 1960 | + ) as close: |
| 1961 | + with client: |
| 1962 | + close.assert_not_called() |
| 1963 | + close.assert_called_once() |
| 1964 | + |
| 1965 | + |
| 1966 | +def test_client_ctx(): |
| 1967 | + transports = [ |
| 1968 | + "grpc", |
| 1969 | + ] |
| 1970 | + for transport in transports: |
| 1971 | + client = CloudShellServiceClient( |
| 1972 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1973 | + ) |
| 1974 | + # Test client calls underlying transport. |
| 1975 | + with mock.patch.object(type(client.transport), "close") as close: |
| 1976 | + close.assert_not_called() |
| 1977 | + with client: |
| 1978 | + pass |
| 1979 | + close.assert_called() |
0 commit comments