3939 LibevConnection = None # noqa
4040
4141
42- @patch ('socket.socket' )
43- @patch ('cassandra.io.libevwrapper.IO' )
44- @patch ('cassandra.io.libevwrapper.Prepare' )
45- @patch ('cassandra.io.libevwrapper.Async' )
46- @patch ('cassandra.io.libevreactor.LibevLoop.maybe_start' )
4742class LibevConnectionTest (unittest .TestCase , ReactorTestMixin ):
4843
4944 connection_class = LibevConnection
@@ -58,8 +53,20 @@ def setUp(self):
5853
5954 def make_msg (self , header , body = six .binary_type ()):
6055 return header + uint32_pack (len (body )) + body
61-
62- def test_successful_connection (self , * args ):
56+ # we patch here rather than as a decorator so that the Mixin can avoid
57+ # specifying patch args to test methods
58+ patchers = [patch (obj ) for obj in
59+ ('socket.socket' ,
60+ 'cassandra.io.libevwrapper.IO' ,
61+ 'cassandra.io.libevwrapper.Prepare' ,
62+ 'cassandra.io.libevwrapper.Async' ,
63+ 'cassandra.io.libevreactor.LibevLoop.maybe_start' )]
64+ for p in patchers :
65+ self .addCleanup (p .stop )
66+ for p in patchers :
67+ p .start ()
68+
69+ def test_successful_connection (self ):
6370 c = self .make_connection ()
6471
6572 # let it write the OptionsMessage
@@ -81,7 +88,7 @@ def test_successful_connection(self, *args):
8188 self .assertTrue (c .connected_event .is_set ())
8289 return c
8390
84- def test_egain_on_buffer_size (self , * args ):
91+ def test_egain_on_buffer_size (self ):
8592 # get a connection that's already fully started
8693 c = self .test_successful_connection ()
8794
@@ -114,7 +121,7 @@ def side_effect(*args):
114121 pos = c ._iobuf .tell ()
115122 self .assertEqual (pos , 4096 + 4096 + 100 )
116123
117- def test_protocol_error (self , * args ):
124+ def test_protocol_error (self ):
118125 c = self .make_connection ()
119126
120127 # let it write the OptionsMessage
@@ -131,7 +138,7 @@ def test_protocol_error(self, *args):
131138 self .assertTrue (c .connected_event .is_set ())
132139 self .assertIsInstance (c .last_error , ProtocolError )
133140
134- def test_error_message_on_startup (self , * args ):
141+ def test_error_message_on_startup (self ):
135142 c = self .make_connection ()
136143
137144 # let it write the OptionsMessage
@@ -156,7 +163,7 @@ def test_error_message_on_startup(self, *args):
156163 self .assertIsInstance (c .last_error , ConnectionException )
157164 self .assertTrue (c .connected_event .is_set ())
158165
159- def test_socket_error_on_write (self , * args ):
166+ def test_socket_error_on_write (self ):
160167 c = self .make_connection ()
161168
162169 # make the OptionsMessage write fail
@@ -168,7 +175,7 @@ def test_socket_error_on_write(self, *args):
168175 self .assertIsInstance (c .last_error , socket_error )
169176 self .assertTrue (c .connected_event .is_set ())
170177
171- def test_blocking_on_write (self , * args ):
178+ def test_blocking_on_write (self ):
172179 c = self .make_connection ()
173180
174181 # make the OptionsMessage write block
@@ -183,7 +190,7 @@ def test_blocking_on_write(self, *args):
183190 self .assertFalse (c .is_defunct )
184191 self .assertTrue (c ._socket .send .call_args is not None )
185192
186- def test_partial_send (self , * args ):
193+ def test_partial_send (self ):
187194 c = self .make_connection ()
188195
189196 # only write the first four bytes of the OptionsMessage
@@ -200,7 +207,7 @@ def test_partial_send(self, *args):
200207 self .assertEqual (expected_writes , c ._socket .send .call_count )
201208 self .assertEqual (last_write_size , len (c ._socket .send .call_args [0 ][0 ]))
202209
203- def test_socket_error_on_read (self , * args ):
210+ def test_socket_error_on_read (self ):
204211 c = self .make_connection ()
205212
206213 # let it write the OptionsMessage
@@ -215,7 +222,7 @@ def test_socket_error_on_read(self, *args):
215222 self .assertIsInstance (c .last_error , socket_error )
216223 self .assertTrue (c .connected_event .is_set ())
217224
218- def test_partial_header_read (self , * args ):
225+ def test_partial_header_read (self ):
219226 c = self .make_connection ()
220227
221228 header = self .make_header_prefix (SupportedMessage )
@@ -241,7 +248,7 @@ def test_partial_header_read(self, *args):
241248 self .assertTrue (c .connected_event .is_set ())
242249 self .assertFalse (c .is_defunct )
243250
244- def test_partial_message_read (self , * args ):
251+ def test_partial_message_read (self ):
245252 c = self .make_connection ()
246253
247254 header = self .make_header_prefix (SupportedMessage )
@@ -268,7 +275,7 @@ def test_partial_message_read(self, *args):
268275 self .assertTrue (c .connected_event .is_set ())
269276 self .assertFalse (c .is_defunct )
270277
271- def test_watchers_are_finished (self , * args ):
278+ def test_watchers_are_finished (self ):
272279 """
273280 Test for asserting that watchers are closed in LibevConnection
274281
0 commit comments