Skip to content

Commit cd10c6b

Browse files
author
Christopher Rabotin
committed
PEP8 formatted.
1 parent c90dd3a commit cd10c6b

File tree

2 files changed

+60
-18
lines changed

2 files changed

+60
-18
lines changed

influxdb/helper.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
class SeriesHelper(object):
12+
1213
'''
1314
Subclassing this helper eases writing data points in bulk.
1415
All data points are immutable, insuring they do not get overwritten.
@@ -62,30 +63,41 @@ def __new__(cls, *args, **kwargs):
6263
try:
6364
_meta = getattr(cls, 'Meta')
6465
except AttributeError:
65-
raise AttributeError('Missing Meta class in {}.'.format(cls.__name__))
66+
raise AttributeError(
67+
'Missing Meta class in {}.'.format(
68+
cls.__name__))
6669

6770
for attr in ['series_name', 'fields']:
6871
try:
6972
setattr(cls, '_' + attr, getattr(_meta, attr))
7073
except AttributeError:
71-
raise AttributeError('Missing {} in {} Meta class.'.format(attr, cls.__name__))
74+
raise AttributeError(
75+
'Missing {} in {} Meta class.'.format(
76+
attr,
77+
cls.__name__))
7278

7379
cls._autocommit = getattr(_meta, 'autocommit', False)
7480

7581
cls._client = getattr(_meta, 'client', None)
7682
if cls._autocommit and not cls._client:
77-
raise AttributeError('In {}, autocommit is set to True, but no client is set.'.format(cls.__name__))
83+
raise AttributeError(
84+
'In {}, autocommit is set to True, but no client is set.'.format(
85+
cls.__name__))
7886

7987
try:
8088
cls._bulk_size = getattr(_meta, 'bulk_size')
8189
if cls._bulk_size < 1 and cls._autocommit:
82-
warn('Definition of bulk_size in {} forced to 1, was less than 1.'.format(cls.__name__))
90+
warn(
91+
'Definition of bulk_size in {} forced to 1, was less than 1.'.format(
92+
cls.__name__))
8393
cls._bulk_size = 1
8494
except AttributeError:
8595
cls._bulk_size = -1
8696
else:
8797
if not cls._autocommit:
88-
warn('Definition of bulk_size in {} has no affect because autocommit is false.'.format(cls.__name__))
98+
warn(
99+
'Definition of bulk_size in {} has no affect because autocommit is false.'.format(
100+
cls.__name__))
89101

90102
cls._datapoints = defaultdict(list)
91103
cls._type = namedtuple(cls.__name__, cls._fields)
@@ -101,7 +113,10 @@ def __init__(self, **kw):
101113
cls = self.__class__
102114

103115
if sorted(cls._fields) != sorted(kw.keys()):
104-
raise NameError('Expected {0}, got {1}.'.format(cls._fields, kw.keys()))
116+
raise NameError(
117+
'Expected {0}, got {1}.'.format(
118+
cls._fields,
119+
kw.keys()))
105120

106121
cls._datapoints[cls._series_name.format(**kw)].append(cls._type(**kw))
107122

tests/influxdb/helper_test.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88

99

1010
class TestSeriesHelper(unittest.TestCase):
11+
1112
@classmethod
1213
def setUpClass(cls):
1314
super(TestSeriesHelper, cls).setUpClass()
1415

15-
TestSeriesHelper.client = InfluxDBClient('host', 8086, 'username', 'password', 'database')
16+
TestSeriesHelper.client = InfluxDBClient(
17+
'host',
18+
8086,
19+
'username',
20+
'password',
21+
'database')
1622

1723
class MySeriesHelper(SeriesHelper):
24+
1825
class Meta:
1926
client = TestSeriesHelper.client
2027
series_name = 'events.stats.{server_name}'
@@ -40,9 +47,13 @@ def testSingleSeriesName(self):
4047
'columns': ['time', 'server_name']}]
4148

4249
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
43-
self.assertTrue(all([el in expectation for el in rcvd]) and all([el in rcvd for el in expectation]), 'Invalid JSON body of time series returned from _json_body_ for one series name: {}.'.format(rcvd))
50+
self.assertTrue(all([el in expectation for el in rcvd]) and all([el in rcvd for el in expectation]),
51+
'Invalid JSON body of time series returned from _json_body_ for one series name: {}.'.format(rcvd))
4452
TestSeriesHelper.MySeriesHelper._reset_()
45-
self.assertEqual(TestSeriesHelper.MySeriesHelper._json_body_(), [], 'Resetting helper did not empty datapoints.')
53+
self.assertEqual(
54+
TestSeriesHelper.MySeriesHelper._json_body_(),
55+
[],
56+
'Resetting helper did not empty datapoints.')
4657

4758
def testSeveralSeriesNames(self):
4859
'''
@@ -66,39 +77,49 @@ def testSeveralSeriesNames(self):
6677
'columns': ['time', 'server_name']}]
6778

6879
rcvd = TestSeriesHelper.MySeriesHelper._json_body_()
69-
self.assertTrue(all([el in expectation for el in rcvd]) and all([el in rcvd for el in expectation]), 'Invalid JSON body of time series returned from _json_body_ for several series names: {}.'.format(rcvd))
80+
self.assertTrue(all([el in expectation for el in rcvd]) and all([el in rcvd for el in expectation]),
81+
'Invalid JSON body of time series returned from _json_body_ for several series names: {}.'.format(rcvd))
7082
TestSeriesHelper.MySeriesHelper._reset_()
71-
self.assertEqual(TestSeriesHelper.MySeriesHelper._json_body_(), [], 'Resetting helper did not empty datapoints.')
83+
self.assertEqual(
84+
TestSeriesHelper.MySeriesHelper._json_body_(),
85+
[],
86+
'Resetting helper did not empty datapoints.')
7287

7388
def testInvalidHelpers(self):
7489
'''
7590
Tests errors in invalid helpers.
7691
'''
7792
class MissingMeta(SeriesHelper):
7893
pass
79-
94+
8095
class MissingClient(SeriesHelper):
96+
8197
class Meta:
8298
series_name = 'events.stats.{server_name}'
8399
fields = ['time', 'server_name']
84100
autocommit = True
85-
101+
86102
class MissingSeriesName(SeriesHelper):
103+
87104
class Meta:
88105
fields = ['time', 'server_name']
89106

90107
class MissingFields(SeriesHelper):
108+
91109
class Meta:
92110
series_name = 'events.stats.{server_name}'
93111

94-
for cls in [MissingMeta, MissingClient, MissingFields, MissingSeriesName]:
95-
self.assertRaises(AttributeError, cls, **{'time': 159, 'server_name': 'us.east-1'})
112+
for cls in [MissingMeta, MissingClient, MissingFields,
113+
MissingSeriesName]:
114+
self.assertRaises(
115+
AttributeError, cls, **{'time': 159, 'server_name': 'us.east-1'})
96116

97117
def testWarnings(self):
98118
'''
99119
Tests warnings for code coverage test.
100120
'''
101121
class WarnBulkSizeZero(SeriesHelper):
122+
102123
class Meta:
103124
client = TestSeriesHelper.client
104125
series_name = 'events.stats.{server_name}'
@@ -107,17 +128,23 @@ class Meta:
107128
autocommit = True
108129

109130
class WarnBulkSizeNoEffect(SeriesHelper):
131+
110132
class Meta:
111133
series_name = 'events.stats.{server_name}'
112134
fields = ['time', 'server_name']
113135
bulk_size = 5
114136
autocommit = False
115-
137+
116138
for cls in [WarnBulkSizeNoEffect, WarnBulkSizeZero]:
117139
with warnings.catch_warnings(record=True) as w:
118140
warnings.simplefilter("always")
119141
try:
120142
cls(time=159, server_name='us.east-1')
121143
except ConnectionError:
122-
pass # Server defined in the client is invalid, we're testing the warning only.
123-
self.assertEqual(len(w), 1, 'Calling {} did not generate exactly one warning.'.format(cls))
144+
# Server defined in the client is invalid, we're testing
145+
# the warning only.
146+
pass
147+
self.assertEqual(
148+
len(w),
149+
1,
150+
'Calling {} did not generate exactly one warning.'.format(cls))

0 commit comments

Comments
 (0)