Skip to content

Commit 5f3fada

Browse files
max-sixtytswast
authored andcommitted
fix & parametrize (#147)
1 parent 9a9a48e commit 5f3fada

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

pandas_gbq/tests/test_gbq.py

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -280,53 +280,31 @@ def test_get_user_account_credentials_returns_credentials(self):
280280
assert isinstance(credentials, Credentials)
281281

282282

283-
@pytest.mark.skip('Currently fails, see '
284-
'https://github.com/pydata/pandas-gbq/pull/125')
285283
class TestGBQUnit(object):
286284

287-
def test_import_google_api_python_client(self):
288-
if not _in_travis_environment():
289-
pytest.skip("Skip if not in travis environment. Extra test to "
290-
"make sure pandas_gbq doesn't break when "
291-
"using google-api-python-client==1.2")
292-
293-
if compat.PY2:
294-
with pytest.raises(ImportError):
295-
from googleapiclient.discovery import build # noqa
296-
from googleapiclient.errors import HttpError # noqa
297-
from apiclient.discovery import build # noqa
298-
from apiclient.errors import HttpError # noqa
299-
else:
300-
from googleapiclient.discovery import build # noqa
301-
from googleapiclient.errors import HttpError # noqa
302-
303285
def test_should_return_credentials_path_set_by_env_var(self):
304286

305287
env = {'PANDAS_GBQ_CREDENTIALS_FILE': '/tmp/dummy.dat'}
306288
with mock.patch.dict('os.environ', env):
307289
assert gbq._get_credentials_file() == '/tmp/dummy.dat'
308290

309-
assert gbq._get_credentials_file() == 'bigquery_credentials.dat'
310-
311-
def test_should_return_bigquery_integers_as_python_ints(self):
312-
result = gbq._parse_entry(1, 'INTEGER')
313-
assert result == int(1)
314-
315-
def test_should_return_bigquery_floats_as_python_floats(self):
316-
result = gbq._parse_entry(1, 'FLOAT')
317-
assert result == float(1)
318-
319-
def test_should_return_bigquery_timestamps_as_numpy_datetime(self):
320-
result = gbq._parse_entry('0e9', 'TIMESTAMP')
321-
assert result == np_datetime64_compat('1970-01-01T00:00:00Z')
322-
323-
def test_should_return_bigquery_booleans_as_python_booleans(self):
324-
result = gbq._parse_entry('false', 'BOOLEAN')
325-
assert not result
326-
327-
def test_should_return_bigquery_strings_as_python_strings(self):
328-
result = gbq._parse_entry('STRING', 'STRING')
329-
assert result == 'STRING'
291+
@pytest.mark.parametrize(
292+
('input', 'type_', 'expected'), [
293+
(1, 'INTEGER', int(1)),
294+
(1, 'FLOAT', float(1)),
295+
pytest.param('false', 'BOOLEAN', False, marks=pytest.mark.xfail),
296+
pytest.param(
297+
'0e9', 'TIMESTAMP',
298+
np_datetime64_compat('1970-01-01T00:00:00Z'),
299+
marks=pytest.mark.xfail),
300+
('STRING', 'STRING', 'STRING'),
301+
])
302+
def test_should_return_bigquery_correctly_typed(
303+
self, input, type_, expected):
304+
result = gbq._parse_data(
305+
dict(fields=[dict(name='x', type=type_, mode='NULLABLE')]),
306+
rows=[[input]]).iloc[0, 0]
307+
assert result == expected
330308

331309
def test_to_gbq_should_fail_if_invalid_table_name_passed(self):
332310
with pytest.raises(gbq.NotFoundException):
@@ -893,7 +871,7 @@ def test_array_of_floats(self):
893871
private_key=_get_private_key_path(),
894872
dialect='standard')
895873
tm.assert_frame_equal(df, DataFrame([[[1.1, 2.2, 3.3], 4]],
896-
columns=["a", "b"]))
874+
columns=["a", "b"]))
897875

898876

899877
class TestToGBQIntegration(object):

0 commit comments

Comments
 (0)