|
10 | 10 |
|
11 | 11 | import numpy as np
|
12 | 12 |
|
13 |
| -from distutils.version import StrictVersion |
14 | 13 | from pandas import compat
|
15 | 14 |
|
16 | 15 | from pandas.compat import u, range
|
|
23 | 22 | TABLE_ID = 'new_test'
|
24 | 23 |
|
25 | 24 |
|
26 |
| -_IMPORTS = False |
27 |
| -_GOOGLE_API_CLIENT_INSTALLED = False |
28 |
| -_GOOGLE_API_CLIENT_VALID_VERSION = False |
29 |
| -_HTTPLIB2_INSTALLED = False |
30 |
| -_GOOGLE_AUTH_INSTALLED = False |
31 |
| -_GOOGLE_AUTH_HTTPLIB2_INSTALLED = False |
32 |
| -_GOOGLE_AUTH_OAUTHLIB_INSTALLED = False |
33 |
| -_SETUPTOOLS_INSTALLED = False |
34 |
| - |
35 |
| - |
36 | 25 | def _skip_if_no_project_id():
|
37 | 26 | if not _get_project_id():
|
38 | 27 | pytest.skip(
|
@@ -87,92 +76,12 @@ def _get_private_key_contents():
|
87 | 76 |
|
88 | 77 |
|
89 | 78 | def _test_imports():
|
90 |
| - global _GOOGLE_API_CLIENT_INSTALLED, _GOOGLE_API_CLIENT_VALID_VERSION, \ |
91 |
| - _GOOGLE_AUTH_INSTALLED, _GOOGLE_AUTH_HTTPLIB2_INSTALLED, \ |
92 |
| - _GOOGLE_AUTH_OAUTHLIB_INSTALLED, _HTTPLIB2_INSTALLED, \ |
93 |
| - _SETUPTOOLS_INSTALLED |
94 |
| - |
95 | 79 | try:
|
96 |
| - import pkg_resources |
97 |
| - _SETUPTOOLS_INSTALLED = True |
| 80 | + import pkg_resources # noqa |
98 | 81 | except ImportError:
|
99 |
| - _SETUPTOOLS_INSTALLED = False |
100 |
| - |
101 |
| - google_api_minimum_version = '1.6.0' |
102 |
| - |
103 |
| - if _SETUPTOOLS_INSTALLED: |
104 |
| - try: |
105 |
| - from googleapiclient.discovery import build # noqa |
106 |
| - from googleapiclient.errors import HttpError # noqa |
107 |
| - |
108 |
| - _GOOGLE_API_CLIENT_INSTALLED = True |
109 |
| - _GOOGLE_API_CLIENT_VERSION = pkg_resources.get_distribution( |
110 |
| - 'google-api-python-client').version |
111 |
| - |
112 |
| - if (StrictVersion(_GOOGLE_API_CLIENT_VERSION) >= |
113 |
| - StrictVersion(google_api_minimum_version)): |
114 |
| - _GOOGLE_API_CLIENT_VALID_VERSION = True |
115 |
| - |
116 |
| - except ImportError: |
117 |
| - _GOOGLE_API_CLIENT_INSTALLED = False |
118 |
| - |
119 |
| - try: |
120 |
| - from google.auth import default # noqa |
121 |
| - from google.auth.exceptions import DefaultCredentialsError # noqa |
122 |
| - from google.oauth2.credentials import Credentials # noqa |
123 |
| - from google.oauth2.service_account import Credentials # noqa |
124 |
| - _GOOGLE_AUTH_INSTALLED = True |
125 |
| - except ImportError: |
126 |
| - _GOOGLE_AUTH_INSTALLED = False |
127 |
| - |
128 |
| - try: |
129 |
| - from google_auth_httplib2 import AuthorizedHttp # noqa |
130 |
| - from google_auth_httplib2 import Request # noqa |
131 |
| - _GOOGLE_AUTH_HTTPLIB2_INSTALLED = True |
132 |
| - except ImportError: |
133 |
| - _GOOGLE_AUTH_HTTPLIB2_INSTALLED = False |
134 |
| - |
135 |
| - try: |
136 |
| - from google_auth_oauthlib.flow import InstalledAppFlow # noqa |
137 |
| - from oauthlib.oauth2.rfc6749.errors import OAuth2Error # noqa |
138 |
| - _GOOGLE_AUTH_OAUTHLIB_INSTALLED = True |
139 |
| - except ImportError: |
140 |
| - _GOOGLE_AUTH_OAUTHLIB_INSTALLED = False |
141 |
| - |
142 |
| - try: |
143 |
| - import httplib2 # noqa |
144 |
| - _HTTPLIB2_INSTALLED = True |
145 |
| - except ImportError: |
146 |
| - _HTTPLIB2_INSTALLED = False |
147 |
| - |
148 |
| - if not _SETUPTOOLS_INSTALLED: |
149 | 82 | raise ImportError('Could not import pkg_resources (setuptools).')
|
150 | 83 |
|
151 |
| - if not _GOOGLE_API_CLIENT_INSTALLED: |
152 |
| - raise ImportError('Could not import Google API Client.') |
153 |
| - |
154 |
| - if not _GOOGLE_API_CLIENT_VALID_VERSION: |
155 |
| - raise ImportError('pandas requires google-api-python-client >= {0} ' |
156 |
| - 'for Google BigQuery support, ' |
157 |
| - 'current version {1}' |
158 |
| - .format(google_api_minimum_version, |
159 |
| - _GOOGLE_API_CLIENT_VERSION)) |
160 |
| - |
161 |
| - if not _GOOGLE_AUTH_INSTALLED: |
162 |
| - raise ImportError( |
163 |
| - 'pandas requires google-auth for Google BigQuery support') |
164 |
| - |
165 |
| - if not _GOOGLE_AUTH_HTTPLIB2_INSTALLED: |
166 |
| - raise ImportError( |
167 |
| - 'pandas requires google-auth-httplib2 for Google BigQuery support') |
168 |
| - |
169 |
| - if not _GOOGLE_AUTH_OAUTHLIB_INSTALLED: |
170 |
| - raise ImportError( |
171 |
| - 'pandas requires google-auth-oauthlib for Google BigQuery support') |
172 |
| - |
173 |
| - if not _HTTPLIB2_INSTALLED: |
174 |
| - raise ImportError( |
175 |
| - 'pandas requires httplib2 for Google BigQuery support') |
| 84 | + gbq._test_google_api_imports() |
176 | 85 |
|
177 | 86 |
|
178 | 87 | def _setup_common():
|
@@ -224,7 +133,7 @@ def clean_gbq_environment(dataset_prefix, private_key=None):
|
224 | 133 | for table_id in all_tables:
|
225 | 134 | try:
|
226 | 135 | table.delete(table_id)
|
227 |
| - except gbq.NotFoundException as e: |
| 136 | + except gbq.NotFoundException: |
228 | 137 | pass
|
229 | 138 | sleep(1)
|
230 | 139 | table_retry = table_retry - 1
|
|
0 commit comments