Skip to content

Commit fab0e4b

Browse files
Fix linting errors on test files
1 parent 768019a commit fab0e4b

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

analytics/test/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import logging
44
import sys
55

6+
67
def all_names():
78
for _, modname, _ in pkgutil.iter_modules(__path__):
89
yield 'analytics.test.' + modname
910

11+
1012
def all():
1113
logging.basicConfig(stream=sys.stderr)
1214
return unittest.defaultTestLoader.loadTestsFromNames(all_names())

analytics/test/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def mock_post_fn(*args, **kwargs):
326326

327327
# the post function should be called 2 times, with a batch size of 10
328328
# each time.
329-
with mock.patch('analytics.consumer.post', side_effect=mock_post_fn) as mock_post:
329+
with mock.patch('analytics.consumer.post', side_effect=mock_post_fn) \
330+
as mock_post:
330331
for _ in range(20):
331332
client.identify('userId', {'trait': 'value'})
332333
time.sleep(1)

analytics/test/consumer.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def test_upload(self):
5252
self.assertTrue(success)
5353

5454
def test_flush_interval(self):
55-
# Put _n_ items in the queue, pausing a little bit more than _flush_interval_
56-
# after each one. The consumer should upload _n_ times.
55+
# Put _n_ items in the queue, pausing a little bit more than
56+
# _flush_interval_ after each one.
57+
# The consumer should upload _n_ times.
5758
q = Queue()
5859
flush_interval = 0.3
5960
consumer = Consumer(q, 'testsecret', flush_at=10,
@@ -71,8 +72,8 @@ def test_flush_interval(self):
7172
self.assertEqual(mock_post.call_count, 3)
7273

7374
def test_multiple_uploads_per_interval(self):
74-
# Put _flush_at*2_ items in the queue at once, then pause for _flush_interval_.
75-
# The consumer should upload 2 times.
75+
# Put _flush_at*2_ items in the queue at once, then pause for
76+
# _flush_interval_. The consumer should upload 2 times.
7677
q = Queue()
7778
flush_interval = 0.5
7879
flush_at = 10
@@ -99,34 +100,38 @@ def test_request(self):
99100
}
100101
consumer.request([track])
101102

102-
def _test_request_retry(self, consumer, expected_exception, exception_count):
103+
def _test_request_retry(self, consumer,
104+
expected_exception, exception_count):
103105

104106
def mock_post(*args, **kwargs):
105107
mock_post.call_count += 1
106108
if mock_post.call_count <= exception_count:
107109
raise expected_exception
108110
mock_post.call_count = 0
109111

110-
with mock.patch('analytics.consumer.post', mock.Mock(side_effect=mock_post)):
112+
with mock.patch('analytics.consumer.post',
113+
mock.Mock(side_effect=mock_post)):
111114
track = {
112115
'type': 'track',
113116
'event': 'python event',
114117
'userId': 'userId'
115118
}
116-
# request() should succeed if the number of exceptions raised is less
117-
# than the retries paramater.
119+
# request() should succeed if the number of exceptions raised is
120+
# less than the retries paramater.
118121
if exception_count <= consumer.retries:
119122
consumer.request([track])
120123
else:
121-
# if exceptions are raised more times than the retries parameter,
122-
# we expect the exception to be returned to the caller.
124+
# if exceptions are raised more times than the retries
125+
# parameter, we expect the exception to be returned to
126+
# the caller.
123127
try:
124128
consumer.request([track])
125129
except type(expected_exception) as exc:
126130
self.assertEqual(exc, expected_exception)
127131
else:
128132
self.fail(
129-
"request() should raise an exception if still failing after %d retries" % consumer.retries)
133+
"request() should raise an exception if still failing "
134+
"after %d retries" % consumer.retries)
130135

131136
def test_request_retry(self):
132137
# we should retry on general errors
@@ -180,10 +185,12 @@ def mock_post_fn(_, data, **kwargs):
180185
res = mock.Mock()
181186
res.status_code = 200
182187
self.assertTrue(len(data.encode()) < 500000,
183-
'batch size (%d) exceeds 500KB limit' % len(data.encode()))
188+
'batch size (%d) exceeds 500KB limit'
189+
% len(data.encode()))
184190
return res
185191

186-
with mock.patch('analytics.request._session.post', side_effect=mock_post_fn) as mock_post:
192+
with mock.patch('analytics.request._session.post',
193+
side_effect=mock_post_fn) as mock_post:
187194
consumer.start()
188195
for _ in range(0, n_msgs + 2):
189196
q.put(track)

analytics/test/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_track(self):
2626
analytics.flush()
2727

2828
def test_identify(self):
29-
analytics.identify('userId', { 'email': '[email protected]' })
29+
analytics.identify('userId', {'email': '[email protected]'})
3030
analytics.flush()
3131

3232
def test_group(self):

analytics/test/request.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ def test_valid_request(self):
1717
self.assertEqual(res.status_code, 200)
1818

1919
def test_invalid_request_error(self):
20-
self.assertRaises(Exception, post, 'testsecret', 'https://api.segment.io', False, '[{]')
20+
self.assertRaises(Exception, post, 'testsecret',
21+
'https://api.segment.io', False, '[{]')
2122

2223
def test_invalid_host(self):
23-
self.assertRaises(Exception, post, 'testsecret', 'api.segment.io/', batch=[])
24+
self.assertRaises(Exception, post, 'testsecret',
25+
'api.segment.io/', batch=[])
2426

2527
def test_datetime_serialization(self):
26-
data = { 'created': datetime(2012, 3, 4, 5, 6, 7, 891011) }
28+
data = {'created': datetime(2012, 3, 4, 5, 6, 7, 891011)}
2729
result = json.dumps(data, cls=DatetimeSerializer)
2830
self.assertEqual(result, '{"created": "2012-03-04T05:06:07.891011"}')
2931

@@ -44,7 +46,7 @@ def test_should_not_timeout(self):
4446

4547
def test_should_timeout(self):
4648
with self.assertRaises(requests.ReadTimeout):
47-
res = post('testsecret', batch=[{
49+
post('testsecret', batch=[{
4850
'userId': 'userId',
4951
'event': 'python event',
5052
'type': 'track'

analytics/test/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ def test_bytes(self):
6565
utils.clean(item)
6666

6767
def test_clean_fn(self):
68-
cleaned = utils.clean({ 'fn': lambda x: x, 'number': 4 })
68+
cleaned = utils.clean({'fn': lambda x: x, 'number': 4})
6969
self.assertEqual(cleaned['number'], 4)
7070
# TODO: fixme, different behavior on python 2 and 3
7171
if 'fn' in cleaned:
7272
self.assertEqual(cleaned['fn'], None)
7373

7474
def test_remove_slash(self):
75-
self.assertEqual('http://segment.io', utils.remove_trailing_slash('http://segment.io/'))
76-
self.assertEqual('http://segment.io', utils.remove_trailing_slash('http://segment.io'))
75+
self.assertEqual('http://segment.io',
76+
utils.remove_trailing_slash('http://segment.io/'))
77+
self.assertEqual('http://segment.io',
78+
utils.remove_trailing_slash('http://segment.io'))

0 commit comments

Comments
 (0)