1717import os
1818from unittest import mock
1919
20+ from google .adk .tools .bigquery import client as bq_client_lib
2021from google .adk .tools .bigquery import metadata_tool
2122from google .adk .tools .bigquery .config import BigQueryToolConfig
23+ import google .auth
2224from google .auth .exceptions import DefaultCredentialsError
2325from google .cloud import bigquery
2426from google .oauth2 .credentials import Credentials
2527
2628
2729@mock .patch .dict (os .environ , {}, clear = True )
28- @mock .patch ( "google.cloud. bigquery.Client. list_datasets" , autospec = True )
29- @mock .patch ( " google.auth. default" , autospec = True )
30+ @mock .patch . object ( bigquery .Client , " list_datasets" , autospec = True )
31+ @mock .patch . object ( google .auth , " default" , autospec = True )
3032def test_list_dataset_ids_no_default_auth (
3133 mock_default_auth , mock_list_datasets
3234):
@@ -53,8 +55,8 @@ def test_list_dataset_ids_no_default_auth(
5355
5456
5557@mock .patch .dict (os .environ , {}, clear = True )
56- @mock .patch ( "google.cloud. bigquery.Client. get_dataset" , autospec = True )
57- @mock .patch ( " google.auth. default" , autospec = True )
58+ @mock .patch . object ( bigquery .Client , " get_dataset" , autospec = True )
59+ @mock .patch . object ( google .auth , " default" , autospec = True )
5860def test_get_dataset_info_no_default_auth (mock_default_auth , mock_get_dataset ):
5961 """Test get_dataset_info tool invocation involves no default auth."""
6062 mock_credentials = mock .create_autospec (Credentials , instance = True )
@@ -80,8 +82,8 @@ def test_get_dataset_info_no_default_auth(mock_default_auth, mock_get_dataset):
8082
8183
8284@mock .patch .dict (os .environ , {}, clear = True )
83- @mock .patch ( "google.cloud. bigquery.Client. list_tables" , autospec = True )
84- @mock .patch ( " google.auth. default" , autospec = True )
85+ @mock .patch . object ( bigquery .Client , " list_tables" , autospec = True )
86+ @mock .patch . object ( google .auth , " default" , autospec = True )
8587def test_list_table_ids_no_default_auth (mock_default_auth , mock_list_tables ):
8688 """Test list_table_ids tool invocation involves no default auth."""
8789 project = "my_project_id"
@@ -108,8 +110,8 @@ def test_list_table_ids_no_default_auth(mock_default_auth, mock_list_tables):
108110
109111
110112@mock .patch .dict (os .environ , {}, clear = True )
111- @mock .patch ( "google.cloud. bigquery.Client. get_table" , autospec = True )
112- @mock .patch ( " google.auth. default" , autospec = True )
113+ @mock .patch . object ( bigquery .Client , " get_table" , autospec = True )
114+ @mock .patch . object ( google .auth , " default" , autospec = True )
113115def test_get_table_info_no_default_auth (mock_default_auth , mock_get_table ):
114116 """Test get_table_info tool invocation involves no default auth."""
115117 mock_credentials = mock .create_autospec (Credentials , instance = True )
@@ -137,8 +139,8 @@ def test_get_table_info_no_default_auth(mock_default_auth, mock_get_table):
137139
138140
139141@mock .patch .dict (os .environ , {}, clear = True )
140- @mock .patch ( "google.cloud. bigquery.Client. get_job" , autospec = True )
141- @mock .patch ( " google.auth. default" , autospec = True )
142+ @mock .patch . object ( bigquery .Client , " get_job" , autospec = True )
143+ @mock .patch . object ( google .auth , " default" , autospec = True )
142144def test_get_job_info_no_default_auth (mock_default_auth , mock_get_job ):
143145 """Test get_job_info tool invocation involves no default auth."""
144146 mock_credentials = mock .create_autospec (Credentials , instance = True )
@@ -166,9 +168,7 @@ def test_get_job_info_no_default_auth(mock_default_auth, mock_get_job):
166168 mock_default_auth .assert_not_called ()
167169
168170
169- @mock .patch (
170- "google.adk.tools.bigquery.client.get_bigquery_client" , autospec = True
171- )
171+ @mock .patch .object (bq_client_lib , "get_bigquery_client" , autospec = True )
172172def test_list_dataset_ids_bq_client_creation (mock_get_bigquery_client ):
173173 """Test BigQuery client creation params during list_dataset_ids tool invocation."""
174174 bq_project = "my_project_id"
@@ -189,9 +189,7 @@ def test_list_dataset_ids_bq_client_creation(mock_get_bigquery_client):
189189 ]
190190
191191
192- @mock .patch (
193- "google.adk.tools.bigquery.client.get_bigquery_client" , autospec = True
194- )
192+ @mock .patch .object (bq_client_lib , "get_bigquery_client" , autospec = True )
195193def test_get_dataset_info_bq_client_creation (mock_get_bigquery_client ):
196194 """Test BigQuery client creation params during get_dataset_info tool invocation."""
197195 bq_project = "my_project_id"
@@ -215,9 +213,7 @@ def test_get_dataset_info_bq_client_creation(mock_get_bigquery_client):
215213 ]
216214
217215
218- @mock .patch (
219- "google.adk.tools.bigquery.client.get_bigquery_client" , autospec = True
220- )
216+ @mock .patch .object (bq_client_lib , "get_bigquery_client" , autospec = True )
221217def test_list_table_ids_bq_client_creation (mock_get_bigquery_client ):
222218 """Test BigQuery client creation params during list_table_ids tool invocation."""
223219 bq_project = "my_project_id"
@@ -241,9 +237,7 @@ def test_list_table_ids_bq_client_creation(mock_get_bigquery_client):
241237 ]
242238
243239
244- @mock .patch (
245- "google.adk.tools.bigquery.client.get_bigquery_client" , autospec = True
246- )
240+ @mock .patch .object (bq_client_lib , "get_bigquery_client" , autospec = True )
247241def test_get_table_info_bq_client_creation (mock_get_bigquery_client ):
248242 """Test BigQuery client creation params during get_table_info tool invocation."""
249243 bq_project = "my_project_id"
@@ -268,9 +262,7 @@ def test_get_table_info_bq_client_creation(mock_get_bigquery_client):
268262 ]
269263
270264
271- @mock .patch (
272- "google.adk.tools.bigquery.client.get_bigquery_client" , autospec = True
273- )
265+ @mock .patch .object (bq_client_lib , "get_bigquery_client" , autospec = True )
274266def test_get_job_info_bq_client_creation (mock_get_bigquery_client ):
275267 """Test BigQuery client creation params during get_table_info tool invocation."""
276268 bq_project = "my_project_id"
0 commit comments