Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 14ce30b

Browse files
committed
Support Python 3
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.
1 parent e25fb5d commit 14ce30b

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.4"
45

56
before_install:
67
- npm install -g typescript

datalab/utils/_http.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ def request(url, args=None, data=None, headers=None, method=None,
132132
if 200 <= response.status < 300:
133133
if raw_response:
134134
return content
135-
return json.loads(str(content, encoding='UTF-8'))
135+
if type(content) == str:
136+
return json.loads(content)
137+
else:
138+
return json.loads(str(content, encoding='UTF-8'))
136139
else:
137140
raise RequestException(response.status, content)
138141
except ValueError:

datalab/utils/_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
from __future__ import unicode_literals
1717
from builtins import str
1818

19-
import httplib
19+
try:
20+
import http.client as httplib
21+
except ImportError:
22+
import httplib
23+
2024
import pytz
2125
import socket
2226
import traceback

tests/bigquery/table_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_table_metadata(self, mock_api_tables_get):
101101
self.assertEqual('Logs', metadata.friendly_name)
102102
self.assertEqual(2, metadata.rows)
103103
self.assertEqual(2, metadata.rows)
104-
self.assertEqual(ts, metadata.created_on)
104+
self.assertTrue(abs((metadata.created_on - ts).total_seconds()) <= 1)
105105
self.assertEqual(None, metadata.expires_on)
106106

107107
@mock.patch('datalab.bigquery._api.Api.tables_get')

tests/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@
9191
runner = unittest.TextTestRunner()
9292
result = runner.run(suite)
9393

94-
sys.exit(len(result.errors))
94+
sys.exit(len(result.errors) + len(result.failures))

tests/stackdriver/monitoring/metric_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_as_dataframe(self, mock_datalab_list_descriptors):
137137
self.assertEqual(dataframe.columns.tolist(), expected_headers)
138138
self.assertEqual(dataframe.columns.names, [None])
139139

140-
self.assertEqual(dataframe.index.tolist(), range(len(METRIC_TYPES)))
140+
self.assertEqual(dataframe.index.tolist(), list(range(len(METRIC_TYPES))))
141141
self.assertEqual(dataframe.index.names, [None])
142142

143143
expected_labels = 'instance_name, device_name'

tests/stackdriver/monitoring/resource_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def test_as_dataframe(self, mock_datalab_list_descriptors):
123123
self.assertEqual(dataframe.columns.tolist(), expected_headers)
124124
self.assertEqual(dataframe.columns.names, [None])
125125

126-
self.assertEqual(dataframe.index.tolist(), range(len(RESOURCE_TYPES)))
126+
self.assertEqual(dataframe.index.tolist(), list(range(len(RESOURCE_TYPES))))
127127
self.assertEqual(dataframe.index.names, [None])
128128

129129
expected_labels = 'instance_id, project_id'

0 commit comments

Comments
 (0)