Skip to content

Commit 4e928b2

Browse files
committed
move patching to setUp
1 parent 10ddff5 commit 4e928b2

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

tests/unit/io/test_asyncorereactor.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def setUp(self):
6464
def make_msg(self, header, body=six.binary_type()):
6565
return header + uint32_pack(len(body)) + body
6666

67-
def test_successful_connection(self, *args):
67+
def test_successful_connection(self):
6868
c = self.make_connection()
6969

7070
# let it write the OptionsMessage
@@ -86,7 +86,7 @@ def test_successful_connection(self, *args):
8686
self.assertTrue(c.connected_event.is_set())
8787
return c
8888

89-
def test_egain_on_buffer_size(self, *args):
89+
def test_egain_on_buffer_size(self):
9090
# get a connection that's already fully started
9191
c = self.test_successful_connection()
9292

@@ -119,7 +119,7 @@ def side_effect(*args):
119119
pos = c._iobuf.tell()
120120
self.assertEqual(pos, 4096 + 4096 + 100)
121121

122-
def test_protocol_error(self, *args):
122+
def test_protocol_error(self):
123123
c = self.make_connection()
124124

125125
# let it write the OptionsMessage
@@ -136,7 +136,7 @@ def test_protocol_error(self, *args):
136136
self.assertTrue(c.connected_event.is_set())
137137
self.assertIsInstance(c.last_error, ProtocolError)
138138

139-
def test_error_message_on_startup(self, *args):
139+
def test_error_message_on_startup(self):
140140
c = self.make_connection()
141141

142142
# let it write the OptionsMessage
@@ -161,7 +161,7 @@ def test_error_message_on_startup(self, *args):
161161
self.assertIsInstance(c.last_error, ConnectionException)
162162
self.assertTrue(c.connected_event.is_set())
163163

164-
def test_socket_error_on_write(self, *args):
164+
def test_socket_error_on_write(self):
165165
c = self.make_connection()
166166

167167
# make the OptionsMessage write fail
@@ -173,7 +173,7 @@ def test_socket_error_on_write(self, *args):
173173
self.assertIsInstance(c.last_error, socket_error)
174174
self.assertTrue(c.connected_event.is_set())
175175

176-
def test_blocking_on_write(self, *args):
176+
def test_blocking_on_write(self):
177177
c = self.make_connection()
178178

179179
# make the OptionsMessage write block
@@ -188,7 +188,7 @@ def test_blocking_on_write(self, *args):
188188
self.assertFalse(c.is_defunct)
189189
self.assertTrue(c.socket.send.call_args is not None)
190190

191-
def test_partial_send(self, *args):
191+
def test_partial_send(self):
192192
c = self.make_connection()
193193

194194
# only write the first four bytes of the OptionsMessage
@@ -205,7 +205,7 @@ def test_partial_send(self, *args):
205205
self.assertEqual(expected_writes, c.socket.send.call_count)
206206
self.assertEqual(last_write_size, len(c.socket.send.call_args[0][0]))
207207

208-
def test_socket_error_on_read(self, *args):
208+
def test_socket_error_on_read(self):
209209
c = self.make_connection()
210210

211211
# let it write the OptionsMessage
@@ -220,7 +220,7 @@ def test_socket_error_on_read(self, *args):
220220
self.assertIsInstance(c.last_error, socket_error)
221221
self.assertTrue(c.connected_event.is_set())
222222

223-
def test_partial_header_read(self, *args):
223+
def test_partial_header_read(self):
224224
c = self.make_connection()
225225

226226
header = self.make_header_prefix(SupportedMessage)
@@ -245,7 +245,7 @@ def test_partial_header_read(self, *args):
245245
self.assertTrue(c.connected_event.is_set())
246246
self.assertFalse(c.is_defunct)
247247

248-
def test_partial_message_read(self, *args):
248+
def test_partial_message_read(self):
249249
c = self.make_connection()
250250

251251
header = self.make_header_prefix(SupportedMessage)
@@ -272,7 +272,7 @@ def test_partial_message_read(self, *args):
272272
self.assertTrue(c.connected_event.is_set())
273273
self.assertFalse(c.is_defunct)
274274

275-
def test_multi_timer_validation(self, *args):
275+
def test_multi_timer_validation(self):
276276
"""
277277
Verify that timer timeouts are honored appropriately
278278
"""

tests/unit/io/test_libevreactor.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
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')
4742
class 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

Comments
 (0)