@@ -119,7 +119,13 @@ async def test_ctor(self):
119119 @CrossSync .pytest
120120 async def test_ctor_super_inits (self ):
121121 from google .cloud .client import ClientWithProject
122+ from google .cloud .bigtable import __version__ as bigtable_version
122123 from google .api_core import client_options as client_options_lib
124+ from google .cloud .bigtable_v2 .services .bigtable .transports .base import (
125+ DEFAULT_CLIENT_INFO ,
126+ )
127+
128+ import copy
123129
124130 project = "project-id"
125131 credentials = AnonymousCredentials ()
@@ -147,13 +153,63 @@ async def test_ctor_super_inits(self):
147153 kwargs = bigtable_client_init .call_args [1 ]
148154 assert kwargs ["credentials" ] == credentials
149155 assert kwargs ["client_options" ] == options_parsed
156+
157+ expected_client_info = copy .copy (DEFAULT_CLIENT_INFO )
158+ expected_client_info .client_library_version = (
159+ f"{ bigtable_version } -data"
160+ if not CrossSync .is_async
161+ else f"{ bigtable_version } -data-async"
162+ )
163+ assert (
164+ kwargs ["client_info" ].to_user_agent ()
165+ == expected_client_info .to_user_agent ()
166+ )
167+ assert (
168+ kwargs ["client_info" ].to_grpc_metadata ()
169+ == expected_client_info .to_grpc_metadata ()
170+ )
171+
150172 # test mixin superclass init was called
151173 assert client_project_init .call_count == 1
152174 kwargs = client_project_init .call_args [1 ]
153175 assert kwargs ["project" ] == project
154176 assert kwargs ["credentials" ] == credentials
155177 assert kwargs ["client_options" ] == options_parsed
156178
179+ @CrossSync .pytest
180+ async def test_ctor_legacy_client (self ):
181+ from google .api_core import client_options as client_options_lib
182+ from google .api_core .gapic_v1 .client_info import ClientInfo
183+
184+ project = "project-id"
185+ credentials = AnonymousCredentials ()
186+ client_info = ClientInfo (gapic_version = "1.2.3" , user_agent = "test-client-" )
187+ client_options = {"api_endpoint" : "foo.bar:1234" }
188+ options_parsed = client_options_lib .from_dict (client_options )
189+ with mock .patch .object (
190+ CrossSync .GapicClient , "__init__"
191+ ) as bigtable_client_init :
192+ try :
193+ client = self ._make_client (
194+ project = project ,
195+ credentials = credentials ,
196+ client_options = options_parsed ,
197+ use_emulator = False ,
198+ _client_info = client_info ,
199+ _disable_background_refresh = True ,
200+ )
201+
202+ assert client ._disable_background_refresh
203+ assert client .client_info is client_info
204+ except TypeError :
205+ pass
206+
207+ # test gapic superclass init was called with the right arguments
208+ assert bigtable_client_init .call_count == 1
209+ kwargs = bigtable_client_init .call_args [1 ]
210+ assert kwargs ["credentials" ] == credentials
211+ assert kwargs ["client_options" ] == options_parsed
212+
157213 @CrossSync .pytest
158214 async def test_ctor_dict_options (self ):
159215 from google .api_core .client_options import ClientOptions
@@ -245,6 +301,22 @@ async def test__start_background_channel_refresh(self):
245301 assert ping_and_warm .call_count == 1
246302 await client .close ()
247303
304+ @CrossSync .pytest
305+ async def test__start_background_channel_refresh_disable_background_refresh (self ):
306+ client = self ._make_client (
307+ project = "project-id" ,
308+ _disable_background_refresh = True ,
309+ )
310+ # should create background tasks for each channel
311+ with mock .patch .object (
312+ client , "_ping_and_warm_instances" , CrossSync .Mock ()
313+ ) as ping_and_warm :
314+ client ._emulator_host = None
315+ client .transport ._grpc_channel = CrossSync .SwappableChannel (mock .Mock )
316+ client ._start_background_channel_refresh ()
317+ assert client ._channel_refresh_task is None
318+ ping_and_warm .assert_not_called ()
319+
248320 @CrossSync .drop
249321 @CrossSync .pytest
250322 @pytest .mark .skipif (
0 commit comments