Skip to content

Commit e21de35

Browse files
committed
tests: update tox config and test scripts to support python 2.6
Define a new py26 env, and add unittest2 as a dependency Add in some simple code that imports unittest2 as unittest if python < 2.7 Fix some .format() calls to add the positional argument specifiers
1 parent ccbffdd commit e21de35

13 files changed

+83
-19
lines changed

influxdb/tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
import unittest
32
import sys
3+
if sys.version_info < (2, 7):
4+
import unittest2 as unittest
5+
else:
6+
import unittest
47
import os
58

69
using_pypy = hasattr(sys, "pypy_version_info")

influxdb/tests/chunked_json_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import unittest
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
48

59
from influxdb import chunked_json
610

influxdb/tests/client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919
import requests.exceptions
2020
import socket
2121
import time
22-
import unittest
2322
import requests_mock
2423
import random
2524
from nose.tools import raises
2625
from mock import patch
2726
import warnings
2827
import mock
28+
import sys
29+
if sys.version_info < (2, 7):
30+
import unittest2 as unittest
31+
else:
32+
import unittest
2933

3034
from influxdb import InfluxDBClient, InfluxDBClusterClient
3135
from influxdb.client import InfluxDBServerError

influxdb/tests/dataframe_client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"""
55
from .client_test import _mocked_session
66

7-
import unittest
7+
import sys
8+
if sys.version_info < (2, 7):
9+
import unittest2 as unittest
10+
else:
11+
import unittest
812
import json
913
import requests_mock
1014
from nose.tools import raises

influxdb/tests/helper_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import unittest
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
48
import warnings
59

610
import mock
@@ -117,7 +121,7 @@ def testSingleSeriesName(self):
117121
self.assertTrue(all([el in expectation for el in rcvd]) and
118122
all([el in rcvd for el in expectation]),
119123
'Invalid JSON body of time series returned from '
120-
'_json_body_ for one series name: {}.'.format(rcvd))
124+
'_json_body_ for one series name: {0}.'.format(rcvd))
121125
TestSeriesHelper.MySeriesHelper._reset_()
122126
self.assertEqual(
123127
TestSeriesHelper.MySeriesHelper._json_body_(),
@@ -183,7 +187,7 @@ def testSeveralSeriesNames(self):
183187
self.assertTrue(all([el in expectation for el in rcvd]) and
184188
all([el in rcvd for el in expectation]),
185189
'Invalid JSON body of time series returned from '
186-
'_json_body_ for several series names: {}.'
190+
'_json_body_ for several series names: {0}.'
187191
.format(rcvd))
188192
TestSeriesHelper.MySeriesHelper._reset_()
189193
self.assertEqual(
@@ -245,7 +249,7 @@ class Meta:
245249
# the warning only.
246250
pass
247251
self.assertEqual(len(w), 1,
248-
'{} call should have generated one warning.'
252+
'{0} call should have generated one warning.'
249253
.format(WarnBulkSizeZero))
250254
self.assertIn('forced to 1', str(w[-1].message),
251255
'Warning message did not contain "forced to 1".')
@@ -267,7 +271,7 @@ class Meta:
267271
warnings.simplefilter("always")
268272
WarnBulkSizeNoEffect(time=159, server_name='us.east-1')
269273
self.assertEqual(len(w), 1,
270-
'{} call should have generated one warning.'
274+
'{0} call should have generated one warning.'
271275
.format(WarnBulkSizeNoEffect))
272276
self.assertIn('has no affect', str(w[-1].message),
273277
'Warning message did not contain "has not affect".')

influxdb/tests/influxdb08/client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import requests
77
import requests.exceptions
88
import socket
9-
import unittest
9+
import sys
10+
if sys.version_info < (2, 7):
11+
import unittest2 as unittest
12+
else:
13+
import unittest
1014
import requests_mock
1115
import random
1216
from nose.tools import raises

influxdb/tests/influxdb08/dataframe_client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"""
55
from .client_test import _mocked_session
66

7-
import unittest
7+
import sys
8+
if sys.version_info < (2, 7):
9+
import unittest2 as unittest
10+
else:
11+
import unittest
812
import json
913
import requests_mock
1014
from nose.tools import raises

influxdb/tests/influxdb08/helper_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import unittest
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
48
import warnings
59

610
import mock
@@ -75,7 +79,7 @@ def testSingleSeriesName(self):
7579
self.assertTrue(all([el in expectation for el in rcvd]) and
7680
all([el in rcvd for el in expectation]),
7781
'Invalid JSON body of time series returned from '
78-
'_json_body_ for one series name: {}.'.format(rcvd))
82+
'_json_body_ for one series name: {0}.'.format(rcvd))
7983
TestSeriesHelper.MySeriesHelper._reset_()
8084
self.assertEqual(
8185
TestSeriesHelper.MySeriesHelper._json_body_(),

influxdb/tests/resultset_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3-
import unittest
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
48

59
from influxdb.exceptions import InfluxDBClientError
610
from influxdb.resultset import ResultSet

influxdb/tests/server_tests/client_test_with_server.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
from functools import partial
1616
import os
1717
import time
18-
import unittest
18+
import sys
19+
if sys.version_info < (2, 7):
20+
import unittest2 as unittest
21+
else:
22+
import unittest
1923
import warnings
2024

2125
# By default, raise exceptions on warnings

influxdb/tests/server_tests/influxdb_instance.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,30 @@
99
import time
1010
import shutil
1111
import subprocess
12-
import unittest
1312
import sys
13+
if sys.version_info < (2, 7):
14+
import unittest2 as unittest
15+
else:
16+
import unittest
1417

1518
from influxdb.tests.misc import is_port_open, get_free_ports
1619

20+
# hack in check_output if it's not defined, like for python 2.6
21+
if "check_output" not in dir( subprocess ):
22+
def f(*popenargs, **kwargs):
23+
if 'stdout' in kwargs:
24+
raise ValueError('stdout argument not allowed, it will be overridden.')
25+
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
26+
output, unused_err = process.communicate()
27+
retcode = process.poll()
28+
if retcode:
29+
cmd = kwargs.get("args")
30+
if cmd is None:
31+
cmd = popenargs[0]
32+
raise subprocess.CalledProcessError(retcode, cmd)
33+
return output
34+
subprocess.check_output = f
35+
1736

1837
class InfluxDbInstance(object):
1938
""" A class to launch of fresh influxdb server instance

influxdb/tests/test_line_protocol.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# -*- coding: utf-8 -*-
22

3-
import unittest
3+
import sys
4+
if sys.version_info < (2, 7):
5+
import unittest2 as unittest
6+
else:
7+
import unittest
8+
49
from influxdb import line_protocol
510

611

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[tox]
2-
envlist = py34, py27, pypy, flake8
2+
envlist = py34, py27, py26, pypy, flake8
33

44
[testenv]
55
passenv = INFLUXDB_PYTHON_INFLUXD_PATH
66
setenv = INFLUXDB_PYTHON_SKIP_SERVER_TESTS=False
77
deps = -r{toxinidir}/requirements.txt
88
-r{toxinidir}/test-requirements.txt
9-
py27,py32,py33,py34: pandas
9+
py27,py32,py33,py34,py26: pandas
10+
py26: unittest2
1011
# Only install pandas with non-pypy interpreters
1112
commands = nosetests -v --with-doctest {posargs}
1213

0 commit comments

Comments
 (0)