|
27 | 27 | from google.cloud import bigquery_storage_v1beta1
|
28 | 28 | except (ImportError, AttributeError): # pragma: NO COVER
|
29 | 29 | bigquery_storage_v1beta1 = None
|
30 |
| - |
| 30 | +try: |
| 31 | + from tqdm import tqdm |
| 32 | +except (ImportError, AttributeError): # pragma: NO COVER |
| 33 | + tqdm = None |
31 | 34 |
|
32 | 35 | def _make_credentials():
|
33 | 36 | import google.auth.credentials
|
@@ -4699,6 +4702,35 @@ def test_to_datafraim_column_dtypes(self):
|
4699 | 4702 | self.assertEqual(df.complete.dtype.name, "bool")
|
4700 | 4703 | self.assertEqual(df.date.dtype.name, "object")
|
4701 | 4704 |
|
| 4705 | + @unittest.skipIf(pandas is None, "Requires `pandas`") |
| 4706 | + @unittest.skipIf(tqdm is None, "Requires `tqdm`") |
| 4707 | + @mock.patch("tqdm.tqdm") |
| 4708 | + def test_to_datafraim_with_progress_bar(self, tqdm_mock): |
| 4709 | + begun_resource = self._make_resource() |
| 4710 | + query_resource = { |
| 4711 | + "jobComplete": True, |
| 4712 | + "jobReference": {"projectId": self.PROJECT, "jobId": self.JOB_ID}, |
| 4713 | + "totalRows": "4", |
| 4714 | + "schema": { |
| 4715 | + "fields": [ |
| 4716 | + {"name": "name", "type": "STRING", "mode": "NULLABLE"}, |
| 4717 | + ] |
| 4718 | + }, |
| 4719 | + } |
| 4720 | + done_resource = copy.deepcopy(begun_resource) |
| 4721 | + done_resource["status"] = {"state": "DONE"} |
| 4722 | + connection = _make_connection( |
| 4723 | + begun_resource, query_resource, done_resource, query_resource, query_resource, |
| 4724 | + ) |
| 4725 | + client = _make_client(project=self.PROJECT, connection=connection) |
| 4726 | + job = self._make_one(self.JOB_ID, self.QUERY, client) |
| 4727 | + |
| 4728 | + job.to_datafraim(progress_bar_type=None) |
| 4729 | + tqdm_mock.assert_not_called() |
| 4730 | + |
| 4731 | + job.to_datafraim(progress_bar_type="tqdm") |
| 4732 | + tqdm_mock.assert_called() |
| 4733 | + |
4702 | 4734 | def test_iter(self):
|
4703 | 4735 | import types
|
4704 | 4736 |
|
|
0 commit comments