@@ -864,7 +864,7 @@ def test_cancel_w_custom_retry(self):
864
864
job = self ._set_properties_job ()
865
865
866
866
api_request_patcher = mock .patch .object (
867
- job ._client ._connection , "api_request" , side_effect = [ValueError , response ],
867
+ job ._client ._connection , "api_request" , side_effect = [ValueError , response ]
868
868
)
869
869
retry = DEFAULT_RETRY .with_deadline (1 ).with_predicate (
870
870
lambda exc : isinstance (exc , ValueError )
@@ -885,7 +885,7 @@ def test_cancel_w_custom_retry(self):
885
885
[
886
886
mock .call (method = "POST" , path = api_path , query_params = {}, timeout = 7.5 ),
887
887
mock .call (
888
- method = "POST" , path = api_path , query_params = {}, timeout = 7.5 ,
888
+ method = "POST" , path = api_path , query_params = {}, timeout = 7.5
889
889
), # was retried once
890
890
],
891
891
)
@@ -1034,7 +1034,6 @@ def test_result_w_retry_wo_state(self):
1034
1034
custom_predicate = mock .Mock ()
1035
1035
custom_predicate .return_value = True
1036
1036
custom_retry = google .api_core .retry .Retry (predicate = custom_predicate )
1037
-
1038
1037
self .assertIs (job .result (retry = custom_retry ), job )
1039
1038
1040
1039
begin_call = mock .call (
@@ -2757,7 +2756,7 @@ def test_cancel_w_bound_client(self):
2757
2756
final_attributes .assert_called_with ({"path" : PATH }, client , job )
2758
2757
2759
2758
conn .api_request .assert_called_once_with (
2760
- method = "POST" , path = PATH , query_params = {}, timeout = None ,
2759
+ method = "POST" , path = PATH , query_params = {}, timeout = None
2761
2760
)
2762
2761
self ._verifyResourceProperties (job , RESOURCE )
2763
2762
@@ -2779,7 +2778,7 @@ def test_cancel_w_alternate_client(self):
2779
2778
2780
2779
conn1 .api_request .assert_not_called ()
2781
2780
conn2 .api_request .assert_called_once_with (
2782
- method = "POST" , path = PATH , query_params = {}, timeout = None ,
2781
+ method = "POST" , path = PATH , query_params = {}, timeout = None
2783
2782
)
2784
2783
self ._verifyResourceProperties (job , RESOURCE )
2785
2784
@@ -3205,7 +3204,7 @@ def test_exists_miss_w_bound_client(self):
3205
3204
final_attributes .assert_called_with ({"path" : PATH }, client , job )
3206
3205
3207
3206
conn .api_request .assert_called_once_with (
3208
- method = "GET" , path = PATH , query_params = {"fields" : "id" }, timeout = None ,
3207
+ method = "GET" , path = PATH , query_params = {"fields" : "id" }, timeout = None
3209
3208
)
3210
3209
3211
3210
def test_exists_hit_w_alternate_client (self ):
@@ -3620,7 +3619,7 @@ def test_exists_miss_w_bound_client(self):
3620
3619
final_attributes .assert_called_with ({"path" : PATH }, client , job )
3621
3620
3622
3621
conn .api_request .assert_called_once_with (
3623
- method = "GET" , path = PATH , query_params = {"fields" : "id" }, timeout = None ,
3622
+ method = "GET" , path = PATH , query_params = {"fields" : "id" }, timeout = None
3624
3623
)
3625
3624
3626
3625
def test_exists_hit_w_alternate_client (self ):
@@ -4812,6 +4811,60 @@ def test_result_with_max_results(self):
4812
4811
tabledata_list_request [1 ]["query_params" ]["maxResults" ], max_results
4813
4812
)
4814
4813
4814
+ def test_result_w_retry (self ):
4815
+ from google .cloud .bigquery .table import RowIterator
4816
+
4817
+ query_resource = {
4818
+ "jobComplete" : False ,
4819
+ "jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
4820
+ }
4821
+ query_resource_done = {
4822
+ "jobComplete" : True ,
4823
+ "jobReference" : {"projectId" : self .PROJECT , "jobId" : self .JOB_ID },
4824
+ "schema" : {"fields" : [{"name" : "col1" , "type" : "STRING" }]},
4825
+ "totalRows" : "2" ,
4826
+ }
4827
+ job_resource = self ._make_resource (started = True )
4828
+ job_resource_done = self ._make_resource (started = True , ended = True )
4829
+ job_resource_done ["configuration" ]["query" ]["destinationTable" ] = {
4830
+ "projectId" : "dest-project" ,
4831
+ "datasetId" : "dest_dataset" ,
4832
+ "tableId" : "dest_table" ,
4833
+ }
4834
+
4835
+ connection = _make_connection (
4836
+ exceptions .NotFound ("not normally retriable" ),
4837
+ query_resource ,
4838
+ exceptions .NotFound ("not normally retriable" ),
4839
+ query_resource_done ,
4840
+ exceptions .NotFound ("not normally retriable" ),
4841
+ job_resource_done ,
4842
+ )
4843
+ client = _make_client (self .PROJECT , connection = connection )
4844
+ job = self ._get_target_class ().from_api_repr (job_resource , client )
4845
+
4846
+ custom_predicate = mock .Mock ()
4847
+ custom_predicate .return_value = True
4848
+ custom_retry = google .api_core .retry .Retry (predicate = custom_predicate )
4849
+
4850
+ self .assertIsInstance (job .result (retry = custom_retry ), RowIterator )
4851
+ query_results_call = mock .call (
4852
+ method = "GET" ,
4853
+ path = f"/projects/{ self .PROJECT } /queries/{ self .JOB_ID } " ,
4854
+ query_params = {"maxResults" : 0 },
4855
+ timeout = None ,
4856
+ )
4857
+ reload_call = mock .call (
4858
+ method = "GET" ,
4859
+ path = f"/projects/{ self .PROJECT } /jobs/{ self .JOB_ID } " ,
4860
+ query_params = {},
4861
+ timeout = None ,
4862
+ )
4863
+
4864
+ connection .api_request .assert_has_calls (
4865
+ [query_results_call , query_results_call , reload_call ]
4866
+ )
4867
+
4815
4868
def test_result_w_empty_schema (self ):
4816
4869
from google .cloud .bigquery .table import _EmptyRowIterator
4817
4870
0 commit comments