|
23 | 23 | TABLE_ID = 'new_test' |
24 | 24 |
|
25 | 25 |
|
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 | 26 | def _skip_if_no_project_id(): |
37 | 27 | if not _get_project_id(): |
38 | 28 | pytest.skip( |
@@ -87,92 +77,12 @@ def _get_private_key_contents(): |
87 | 77 |
|
88 | 78 |
|
89 | 79 | 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 | 80 | try: |
96 | 81 | import pkg_resources |
97 | | - _SETUPTOOLS_INSTALLED = True |
98 | 82 | 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 | 83 | raise ImportError('Could not import pkg_resources (setuptools).') |
150 | 84 |
|
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') |
| 85 | + gbq._test_google_api_imports() |
176 | 86 |
|
177 | 87 |
|
178 | 88 | def _setup_common(): |
|
0 commit comments