Skip to content

Convert to Python3 #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
language: python

python:
- "2.7"
- "3.6"
- "3.7-dev" # 3.7 development branch

install:
- python setup.py develop
- pip install tox
script: tox -e $TOXENV
notifications:
email: false
env:
- TOXENV=py27
- TOXENV=py33
- TOXENV=py34
- TOXENV=nightly
- TOXENV=pypy
7 changes: 5 additions & 2 deletions bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from googleapiclient.errors import HttpError
from httplib2 import Http

if sys.version_info >= (3, 0):
basestring = str

BIGQUERY_SCOPE = [
'https://www.googleapis.com/auth/bigquery'
]
Expand Down Expand Up @@ -1213,7 +1216,7 @@ def wait_for_job(self, job, interval=5, timeout=60):
jobId=job_id)
job_resource = request.execute()
self._raise_executing_exception_if_error(job_resource)
complete = job_resource.get('status').get('state') == u'DONE'
complete = job_resource.get('status').get('state') == 'DONE'
elapsed_time = time() - start_time

# raise exceptions if timeout
Expand Down Expand Up @@ -1489,7 +1492,7 @@ def _filter_tables_by_time(self, tables, start_time, end_time):
Table names that are inside the time range
"""

return [table_name for (table_name, unix_seconds) in tables.items()
return [table_name for (table_name, unix_seconds) in list(tables.items())
if self._in_range(start_time, end_time, unix_seconds)]

def _in_range(self, start_time, end_time, time):
Expand Down
2 changes: 1 addition & 1 deletion bigquery/query_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _render_select(selections):
return 'SELECT *'

rendered_selections = []
for name, options in selections.items():
for name, options in list(selections.items()):
if not isinstance(options, list):
options = [options]

Expand Down
32 changes: 16 additions & 16 deletions bigquery/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ def setUp(self):
def test_completed_jobs(self):
"""Ensure we can detect completed jobs"""

return_values = [{'status': {'state': u'RUNNING'},
return_values = [{'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}},
{'status': {'state': u'DONE'},
{'status': {'state': 'DONE'},
'jobReference': {'jobId': "testJob"}}]

def side_effect(*args, **kwargs):
Expand All @@ -667,7 +667,7 @@ def side_effect(*args, **kwargs):

job_resource = self.client.wait_for_job(
{'jobReference': {'jobId': "testJob"},
'status': {'state': u'RUNNING'}},
'status': {'state': 'RUNNING'}},
interval=.01,
timeout=.05)

Expand All @@ -676,7 +676,7 @@ def side_effect(*args, **kwargs):

def test_timeout_error(self):
"""Ensure that timeout raise exceptions"""
incomplete_job = {'status': {'state': u'RUNNING'},
incomplete_job = {'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}}

self.api_mock.jobs().get().execute.return_value = incomplete_job
Expand All @@ -685,7 +685,7 @@ def test_timeout_error(self):

def test_wait_job_http_error(self):
""" Test wait job with http error"""
job = {'status': {'state': u'RUNNING'},
job = {'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}}

expected_result = {
Expand All @@ -709,7 +709,7 @@ def test_wait_job_http_error(self):

def test_wait_job_error_result(self):
""" Test wait job with error result"""
job = {'status': {'state': u'RUNNING'},
job = {'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}}

expected_result = {
Expand All @@ -733,9 +733,9 @@ def test_wait_job_error_result(self):
def test_accepts_job_id(self):
"""Ensure it accepts a job Id rather than a full job resource"""

return_values = [{'status': {'state': u'RUNNING'},
return_values = [{'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}},
{'status': {'state': u'DONE'},
{'status': {'state': 'DONE'},
'jobReference': {'jobId': "testJob"}}]

def side_effect(*args, **kwargs):
Expand All @@ -751,9 +751,9 @@ def side_effect(*args, **kwargs):
self.assertIsInstance(job_resource, dict)

def test_accepts_integer_job_id(self):
return_values = [{'status': {'state': u'RUNNING'},
return_values = [{'status': {'state': 'RUNNING'},
'jobReference': {'jobId': "testJob"}},
{'status': {'state': u'DONE'},
{'status': {'state': 'DONE'},
'jobReference': {'jobId': "testJob"}}]

def side_effect(*args, **kwargs):
Expand Down Expand Up @@ -784,7 +784,7 @@ def setUp(self):

def test_csv_job_body_constructed_correctly(self):
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down Expand Up @@ -843,7 +843,7 @@ def test_csv_job_body_constructed_correctly(self):

def test_json_job_body_constructed_correctly(self):
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down Expand Up @@ -938,7 +938,7 @@ def test_skip_leading_rows_exception_if_not_csv(self):
def test_accepts_single_source_uri(self):
"""Ensure that a source_uri accepts a non-list"""
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down Expand Up @@ -1033,7 +1033,7 @@ def setUp(self):
def test_export(self, mock_generate_hex):
""" Ensure that export is working in normal circumstances """
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def setUp(self):
def test_write(self):
""" Ensure that write is working in normal circumstances."""
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_write(self):
def test_write_maxbilltier(self):
""" Ensure that write is working when maximumBillingTier is set"""
expected_result = {
'status': {'state': u'RUNNING'},
'status': {'state': 'RUNNING'},
}

body = {
Expand Down
2 changes: 1 addition & 1 deletion bigquery/tests/test_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_str_is_string(self):
six.assertCountEqual(self, bigquery_type("Bob"), 'string')

def test_unicode_is_string(self):
six.assertCountEqual(self, bigquery_type(u"Here is a happy face \u263A"),
six.assertCountEqual(self, bigquery_type("Here is a happy face \u263A"),
'string')

def test_int_is_integer(self):
Expand Down