|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +importconcurrent.futures |
15 | 16 | importcopy |
16 | 17 | importjson |
17 | 18 |
|
|
36 | 37 | except (ImportError,AttributeError):# pragma: NO COVER |
37 | 38 | geopandas=None |
38 | 39 | try: |
39 | | -fromtqdmimporttqdm |
| 40 | +importtqdm |
40 | 41 | except (ImportError,AttributeError):# pragma: NO COVER |
41 | 42 | tqdm=None |
42 | 43 |
|
@@ -300,7 +301,8 @@ def test_to_arrow_max_results_no_progress_bar(): |
300 | 301 |
|
301 | 302 |
|
302 | 303 | @pytest.mark.skipif(tqdmisNone,reason="Requires `tqdm`") |
303 | | -deftest_to_arrow_w_tqdm_w_query_plan(): |
| 304 | +@mock.patch("tqdm.tqdm") |
| 305 | +deftest_to_arrow_w_tqdm_w_query_plan(tqdm_mock): |
304 | 306 | fromgoogle.cloud.bigqueryimporttable |
305 | 307 | fromgoogle.cloud.bigquery.jobimportQueryJobastarget_class |
306 | 308 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
@@ -338,23 +340,26 @@ def test_to_arrow_w_tqdm_w_query_plan(): |
338 | 340 | result_patch=mock.patch( |
339 | 341 | "google.cloud.bigquery.job.QueryJob.result", |
340 | 342 | side_effect=[ |
| 343 | +concurrent.futures.TimeoutError, |
| 344 | +concurrent.futures.TimeoutError, |
341 | 345 | row_iterator, |
342 | 346 | ], |
343 | 347 | ) |
344 | 348 |
|
345 | | -withresult_patchasresult_patch_tqdm,reload_patch: |
| 349 | +withresult_patchastqdm_mock,reload_patch: |
346 | 350 | tbl=job.to_arrow(progress_bar_type="tqdm",create_bqstorage_client=False) |
347 | 351 |
|
348 | | -assertresult_patch_tqdm.call_count==1 |
| 352 | +asserttqdm_mock.call_count==3 |
349 | 353 | assertisinstance(tbl,pyarrow.Table) |
350 | 354 | asserttbl.num_rows==2 |
351 | | -result_patch_tqdm.assert_called_with( |
| 355 | +tqdm_mock.assert_called_with( |
352 | 356 | timeout=_PROGRESS_BAR_UPDATE_INTERVAL,max_results=None |
353 | 357 | ) |
354 | 358 |
|
355 | 359 |
|
356 | 360 | @pytest.mark.skipif(tqdmisNone,reason="Requires `tqdm`") |
357 | | -deftest_to_arrow_w_tqdm_w_pending_status(): |
| 361 | +@mock.patch("tqdm.tqdm") |
| 362 | +deftest_to_arrow_w_tqdm_w_pending_status(tqdm_mock): |
358 | 363 | fromgoogle.cloud.bigqueryimporttable |
359 | 364 | fromgoogle.cloud.bigquery.jobimportQueryJobastarget_class |
360 | 365 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
@@ -391,16 +396,16 @@ def test_to_arrow_w_tqdm_w_pending_status(): |
391 | 396 | ) |
392 | 397 | result_patch=mock.patch( |
393 | 398 | "google.cloud.bigquery.job.QueryJob.result", |
394 | | -side_effect=[row_iterator], |
| 399 | +side_effect=[concurrent.futures.TimeoutError,row_iterator], |
395 | 400 | ) |
396 | 401 |
|
397 | | -withresult_patchasresult_patch_tqdm,reload_patch: |
| 402 | +withresult_patchastqdm_mock,reload_patch: |
398 | 403 | tbl=job.to_arrow(progress_bar_type="tqdm",create_bqstorage_client=False) |
399 | 404 |
|
400 | | -assertresult_patch_tqdm.call_count==1 |
| 405 | +asserttqdm_mock.call_count==2 |
401 | 406 | assertisinstance(tbl,pyarrow.Table) |
402 | 407 | asserttbl.num_rows==2 |
403 | | -result_patch_tqdm.assert_called_with( |
| 408 | +tqdm_mock.assert_called_with( |
404 | 409 | timeout=_PROGRESS_BAR_UPDATE_INTERVAL,max_results=None |
405 | 410 | ) |
406 | 411 |
|
@@ -748,7 +753,8 @@ def test_to_dataframe_with_progress_bar(tqdm_mock): |
748 | 753 |
|
749 | 754 |
|
750 | 755 | @pytest.mark.skipif(tqdmisNone,reason="Requires `tqdm`") |
751 | | -deftest_to_dataframe_w_tqdm_pending(): |
| 756 | +@mock.patch("tqdm.tqdm") |
| 757 | +deftest_to_dataframe_w_tqdm_pending(tqdm_mock): |
752 | 758 | fromgoogle.cloud.bigqueryimporttable |
753 | 759 | fromgoogle.cloud.bigquery.jobimportQueryJobastarget_class |
754 | 760 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
@@ -787,23 +793,24 @@ def test_to_dataframe_w_tqdm_pending(): |
787 | 793 | ) |
788 | 794 | result_patch=mock.patch( |
789 | 795 | "google.cloud.bigquery.job.QueryJob.result", |
790 | | -side_effect=[row_iterator], |
| 796 | +side_effect=[concurrent.futures.TimeoutError,row_iterator], |
791 | 797 | ) |
792 | 798 |
|
793 | | -withresult_patchasresult_patch_tqdm,reload_patch: |
| 799 | +withresult_patchastqdm_mock,reload_patch: |
794 | 800 | df=job.to_dataframe(progress_bar_type="tqdm",create_bqstorage_client=False) |
795 | 801 |
|
796 | | -assertresult_patch_tqdm.call_count==1 |
| 802 | +asserttqdm_mock.call_count==2 |
797 | 803 | assertisinstance(df,pandas.DataFrame) |
798 | 804 | assertlen(df)==4# verify the number of rows |
799 | 805 | assertlist(df)== ["name","age"]# verify the column names |
800 | | -result_patch_tqdm.assert_called_with( |
| 806 | +tqdm_mock.assert_called_with( |
801 | 807 | timeout=_PROGRESS_BAR_UPDATE_INTERVAL,max_results=None |
802 | 808 | ) |
803 | 809 |
|
804 | 810 |
|
805 | 811 | @pytest.mark.skipif(tqdmisNone,reason="Requires `tqdm`") |
806 | | -deftest_to_dataframe_w_tqdm(): |
| 812 | +@mock.patch("tqdm.tqdm") |
| 813 | +deftest_to_dataframe_w_tqdm(tqdm_mock): |
807 | 814 | fromgoogle.cloud.bigqueryimporttable |
808 | 815 | fromgoogle.cloud.bigquery.jobimportQueryJobastarget_class |
809 | 816 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
@@ -843,24 +850,27 @@ def test_to_dataframe_w_tqdm(): |
843 | 850 | result_patch=mock.patch( |
844 | 851 | "google.cloud.bigquery.job.QueryJob.result", |
845 | 852 | side_effect=[ |
| 853 | +concurrent.futures.TimeoutError, |
| 854 | +concurrent.futures.TimeoutError, |
846 | 855 | row_iterator, |
847 | 856 | ], |
848 | 857 | ) |
849 | 858 |
|
850 | | -withresult_patchasresult_patch_tqdm,reload_patch: |
| 859 | +withresult_patchastqdm_mock,reload_patch: |
851 | 860 | df=job.to_dataframe(progress_bar_type="tqdm",create_bqstorage_client=False) |
852 | 861 |
|
853 | | -assertresult_patch_tqdm.call_count==1 |
| 862 | +asserttqdm_mock.call_count==3 |
854 | 863 | assertisinstance(df,pandas.DataFrame) |
855 | 864 | assertlen(df)==4# verify the number of rows |
856 | 865 | assertlist(df), ["name","age"]# verify the column names |
857 | | -result_patch_tqdm.assert_called_with( |
| 866 | +tqdm_mock.assert_called_with( |
858 | 867 | timeout=_PROGRESS_BAR_UPDATE_INTERVAL,max_results=None |
859 | 868 | ) |
860 | 869 |
|
861 | 870 |
|
862 | 871 | @pytest.mark.skipif(tqdmisNone,reason="Requires `tqdm`") |
863 | | -deftest_to_dataframe_w_tqdm_max_results(): |
| 872 | +@mock.patch("tqdm.tqdm") |
| 873 | +deftest_to_dataframe_w_tqdm_max_results(tqdm_mock): |
864 | 874 | fromgoogle.cloud.bigqueryimporttable |
865 | 875 | fromgoogle.cloud.bigquery.jobimportQueryJobastarget_class |
866 | 876 | fromgoogle.cloud.bigquery.schemaimportSchemaField |
@@ -894,16 +904,16 @@ def test_to_dataframe_w_tqdm_max_results(): |
894 | 904 | ) |
895 | 905 | result_patch=mock.patch( |
896 | 906 | "google.cloud.bigquery.job.QueryJob.result", |
897 | | -side_effect=[row_iterator], |
| 907 | +side_effect=[concurrent.futures.TimeoutError,row_iterator], |
898 | 908 | ) |
899 | 909 |
|
900 | | -withresult_patchasresult_patch_tqdm,reload_patch: |
| 910 | +withresult_patchastqdm_mock,reload_patch: |
901 | 911 | job.to_dataframe( |
902 | 912 | progress_bar_type="tqdm",create_bqstorage_client=False,max_results=3 |
903 | 913 | ) |
904 | 914 |
|
905 | | -assertresult_patch_tqdm.call_count==1 |
906 | | -result_patch_tqdm.assert_called_with( |
| 915 | +asserttqdm_mock.call_count==2 |
| 916 | +tqdm_mock.assert_called_with( |
907 | 917 | timeout=_PROGRESS_BAR_UPDATE_INTERVAL,max_results=3 |
908 | 918 | ) |
909 | 919 |
|
|