@@ -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 )
0 commit comments