Skip to content

Commit

Permalink
Support Python 3
Browse files Browse the repository at this point in the history
We had tried to support Python 3 previously, but we were not testing
under Python 3 to ensure that we maintained that support.

This change adds testing for Python 3 and fixes the breakages that have
crept in since our previous effort

This also fixes a transient error in the bigquery tests where
the test only passed if they completed in less than 1 microsecond.
  • Loading branch information
ojarjur committed Aug 19, 2016
1 parent e25fb5d commit 14ce30b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
python:
- "2.7"
- "3.4"

before_install:
- npm install -g typescript
Expand Down
5 changes: 4 additions & 1 deletion datalab/utils/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ def request(url, args=None, data=None, headers=None, method=None,
if 200 <= response.status < 300:
if raw_response:
return content
return json.loads(str(content, encoding='UTF-8'))
if type(content) == str:
return json.loads(content)
else:
return json.loads(str(content, encoding='UTF-8'))
else:
raise RequestException(response.status, content)
except ValueError:
Expand Down
6 changes: 5 additions & 1 deletion datalab/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from __future__ import unicode_literals
from builtins import str

import httplib
try:
import http.client as httplib
except ImportError:
import httplib

import pytz
import socket
import traceback
Expand Down
2 changes: 1 addition & 1 deletion tests/bigquery/table_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_table_metadata(self, mock_api_tables_get):
self.assertEqual('Logs', metadata.friendly_name)
self.assertEqual(2, metadata.rows)
self.assertEqual(2, metadata.rows)
self.assertEqual(ts, metadata.created_on)
self.assertTrue(abs((metadata.created_on - ts).total_seconds()) <= 1)
self.assertEqual(None, metadata.expires_on)

@mock.patch('datalab.bigquery._api.Api.tables_get')
Expand Down
2 changes: 1 addition & 1 deletion tests/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
runner = unittest.TextTestRunner()
result = runner.run(suite)

sys.exit(len(result.errors))
sys.exit(len(result.errors) + len(result.failures))
2 changes: 1 addition & 1 deletion tests/stackdriver/monitoring/metric_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_as_dataframe(self, mock_datalab_list_descriptors):
self.assertEqual(dataframe.columns.tolist(), expected_headers)
self.assertEqual(dataframe.columns.names, [None])

self.assertEqual(dataframe.index.tolist(), range(len(METRIC_TYPES)))
self.assertEqual(dataframe.index.tolist(), list(range(len(METRIC_TYPES))))
self.assertEqual(dataframe.index.names, [None])

expected_labels = 'instance_name, device_name'
Expand Down
2 changes: 1 addition & 1 deletion tests/stackdriver/monitoring/resource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_as_dataframe(self, mock_datalab_list_descriptors):
self.assertEqual(dataframe.columns.tolist(), expected_headers)
self.assertEqual(dataframe.columns.names, [None])

self.assertEqual(dataframe.index.tolist(), range(len(RESOURCE_TYPES)))
self.assertEqual(dataframe.index.tolist(), list(range(len(RESOURCE_TYPES))))
self.assertEqual(dataframe.index.names, [None])

expected_labels = 'instance_id, project_id'
Expand Down

0 comments on commit 14ce30b

Please sign in to comment.