Skip to content

Commit 49365e4

Browse files
author
Chris Grinolds
committed
Updated test suite to handle changes to gbq.py
1 parent 0ebc120 commit 49365e4

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

pandas/io/tests/test_gbq.py

+62-1
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,77 @@
2222

2323
VERSION = platform.python_version()
2424

25+
_IMPORTS = False
26+
_GOOGLE_API_CLIENT_INSTALLED = False
27+
_GOOGLE_API_CLIENT_VALID_VERSION = False
28+
_HTTPLIB2_INSTALLED = False
29+
_SETUPTOOLS_INSTALLED = False
30+
2531
def missing_bq():
2632
try:
2733
subprocess.call('bq')
2834
return False
2935
except OSError:
3036
return True
3137

38+
def _test_imports():
39+
if not compat.PY3:
40+
41+
global _GOOGLE_API_CLIENT_INSTALLED, _GOOGLE_API_CLIENT_VALID_VERSION, \
42+
_HTTPLIB2_INSTALLED, _SETUPTOOLS_INSTALLED
43+
44+
try:
45+
import pkg_resources
46+
_SETUPTOOLS_INSTALLED = True
47+
except ImportError:
48+
_SETUPTOOLS_INSTALLED = False
49+
50+
if _SETUPTOOLS_INSTALLED:
51+
try:
52+
from apiclient.discovery import build
53+
from apiclient.errors import HttpError
54+
55+
from oauth2client.client import OAuth2WebServerFlow
56+
from oauth2client.client import AccessTokenRefreshError
57+
58+
from oauth2client.file import Storage
59+
from oauth2client.tools import run_flow
60+
_GOOGLE_API_CLIENT_INSTALLED=True
61+
_GOOGLE_API_CLIENT_VERSION = pkg_resources.get_distribution('google-api-python-client').version
62+
63+
if LooseVersion(_GOOGLE_API_CLIENT_VERSION) >= '1.2.0':
64+
_GOOGLE_API_CLIENT_VALID_VERSION = True
65+
66+
except ImportError:
67+
_GOOGLE_API_CLIENT_INSTALLED = False
68+
69+
70+
try:
71+
import httplib2
72+
_HTTPLIB2_INSTALLED = True
73+
except ImportError:
74+
_HTTPLIB2_INSTALLED = False
75+
76+
77+
if compat.PY3:
78+
raise NotImplementedError("Google's libraries do not support Python 3 yet")
79+
80+
if not _SETUPTOOLS_INSTALLED:
81+
raise ImportError('Could not import pkg_resources (setuptools).')
82+
83+
if not _GOOGLE_API_CLIENT_INSTALLED:
84+
raise ImportError('Could not import Google API Client.')
85+
86+
if not _GOOGLE_API_CLIENT_VALID_VERSION:
87+
raise ImportError("pandas requires google-api-python-client >= 1.2.0 for Google "
88+
"BigQuery support, current version " + _GOOGLE_API_CLIENT_VERSION)
89+
90+
if not _HTTPLIB2_INSTALLED:
91+
raise ImportError("pandas requires httplib2 for Google BigQuery support")
92+
3293
def test_requirements():
3394
try:
34-
gbq._test_imports()
95+
_test_imports()
3596
except (ImportError, NotImplementedError) as import_exception:
3697
raise nose.SkipTest(import_exception)
3798

0 commit comments

Comments
 (0)