@@ -166,7 +166,8 @@ def _log_error(*args):
166166 errors_logged .append (args )
167167
168168 with (
169- socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as sock , pytest .raises (OSError ),
169+ socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as sock ,
170+ pytest .raises (OSError ),
170171 patch .object (netutils .log , "error" , _log_error ),
171172 patch ("socket.socket.setsockopt" , side_effect = OSError ),
172173 ):
@@ -178,7 +179,6 @@ def _log_error(*args):
178179 )
179180
180181
181-
182182@pytest .mark .skipif (not hasattr (socket , "SO_REUSEPORT" ), reason = "System does not have SO_REUSEPORT" )
183183def test_set_so_reuseport_if_available_is_present ():
184184 """Test that setting socket.SO_REUSEPORT only OSError errno.ENOPROTOOPT is trapped."""
@@ -197,21 +197,26 @@ def test_set_so_reuseport_if_available_not_present():
197197 socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as sock ,
198198 patch ("socket.socket.setsockopt" , side_effect = OSError ),
199199 ):
200- netutils .set_so_reuseport_if_available (sock )
200+ netutils .set_so_reuseport_if_available (sock )
201201
202202
203203def test_set_mdns_port_socket_options_for_ip_version ():
204204 """Test OSError with errno with EINVAL and bind address ''.
205205
206206 from setsockopt IP_MULTICAST_TTL does not raise."""
207207 with socket .socket (socket .AF_INET , socket .SOCK_DGRAM ) as sock :
208-
209208 # Should raise on EPERM always
210- with pytest .raises (OSError ), patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EPERM , None )):
209+ with (
210+ pytest .raises (OSError ),
211+ patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EPERM , None )),
212+ ):
211213 netutils .set_mdns_port_socket_options_for_ip_version (sock , ("" ,), r .IPVersion .V4Only )
212214
213215 # Should raise on EINVAL always when bind address is not ''
214- with pytest .raises (OSError ), patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EINVAL , None )):
216+ with (
217+ pytest .raises (OSError ),
218+ patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EINVAL , None )),
219+ ):
215220 netutils .set_mdns_port_socket_options_for_ip_version (sock , ("127.0.0.1" ,), r .IPVersion .V4Only )
216221
217222 # Should not raise on EINVAL when bind address is ''
@@ -224,7 +229,10 @@ def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
224229 interface = "127.0.0.1"
225230
226231 # EPERM should always raise
227- with pytest .raises (OSError ), patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EPERM , None )):
232+ with (
233+ pytest .raises (OSError ),
234+ patch ("socket.socket.setsockopt" , side_effect = OSError (errno .EPERM , None )),
235+ ):
228236 netutils .add_multicast_member (sock , interface )
229237
230238 # EADDRINUSE should return False
@@ -244,7 +252,10 @@ def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
244252 assert netutils .add_multicast_member (sock , interface ) is False
245253
246254 # ENODEV should raise for ipv4
247- with pytest .raises (OSError ), patch ("socket.socket.setsockopt" , side_effect = OSError (errno .ENODEV , None )):
255+ with (
256+ pytest .raises (OSError ),
257+ patch ("socket.socket.setsockopt" , side_effect = OSError (errno .ENODEV , None )),
258+ ):
248259 assert netutils .add_multicast_member (sock , interface ) is False
249260
250261 # ENODEV should return False for ipv6
@@ -263,7 +274,9 @@ def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
263274 caplog .clear ()
264275 with (
265276 patch .object (sys , "platform" , "linux" ),
266- patch ("socket.socket.setsockopt" , side_effect = OSError (errno .ENOBUFS , "No buffer space available" )),
277+ patch (
278+ "socket.socket.setsockopt" , side_effect = OSError (errno .ENOBUFS , "No buffer space available" )
279+ ),
267280 ):
268281 assert netutils .add_multicast_member (sock , interface ) is False
269282 assert "No buffer space available" in caplog .text
@@ -273,7 +286,9 @@ def test_add_multicast_member(caplog: pytest.LogCaptureFixture) -> None:
273286 caplog .clear ()
274287 with (
275288 patch .object (sys , "platform" , "darwin" ),
276- patch ("socket.socket.setsockopt" , side_effect = OSError (errno .ENOBUFS , "No buffer space available" )),
289+ patch (
290+ "socket.socket.setsockopt" , side_effect = OSError (errno .ENOBUFS , "No buffer space available" )
291+ ),
277292 ):
278293 assert netutils .add_multicast_member (sock , interface ) is False
279294 assert "No buffer space available" in caplog .text
0 commit comments