Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1637487

Browse files
committed
Skip test if the path is too long for a AF_UNIX socket
1 parent 6ec29e2 commit 1637487

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Lib/test/test_socket.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4268,17 +4268,29 @@ def encoded(self, path):
42684268
"system encoding {1!r}".format(
42694269
path, sys.getfilesystemencoding()))
42704270

4271+
def bind(self, sock, path):
4272+
# Bind the socket
4273+
try:
4274+
sock.bind(path)
4275+
except OSError as e:
4276+
if str(e) == "AF_UNIX path too long":
4277+
self.skipTest(
4278+
"Pathname {0!a} is too long to serve as a AF_UNIX path"
4279+
.format(path))
4280+
else:
4281+
raise
4282+
42714283
def testStrAddr(self):
42724284
# Test binding to and retrieving a normal string pathname.
42734285
path = os.path.abspath(support.TESTFN)
4274-
self.sock.bind(path)
4286+
self.bind(self.sock, path)
42754287
self.addCleanup(support.unlink, path)
42764288
self.assertEqual(self.sock.getsockname(), path)
42774289

42784290
def testBytesAddr(self):
42794291
# Test binding to a bytes pathname.
42804292
path = os.path.abspath(support.TESTFN)
4281-
self.sock.bind(self.encoded(path))
4293+
self.bind(self.sock, self.encoded(path))
42824294
self.addCleanup(support.unlink, path)
42834295
self.assertEqual(self.sock.getsockname(), path)
42844296

@@ -4287,7 +4299,7 @@ def testSurrogateescapeBind(self):
42874299
# non-ASCII bytes supplied using surrogateescape encoding.
42884300
path = os.path.abspath(support.TESTFN_UNICODE)
42894301
b = self.encoded(path)
4290-
self.sock.bind(b.decode("ascii", "surrogateescape"))
4302+
self.bind(self.sock, b.decode("ascii", "surrogateescape"))
42914303
self.addCleanup(support.unlink, path)
42924304
self.assertEqual(self.sock.getsockname(), path)
42934305

@@ -4297,7 +4309,7 @@ def testUnencodableAddr(self):
42974309
if support.TESTFN_UNENCODABLE is None:
42984310
self.skipTest("No unencodable filename available")
42994311
path = os.path.abspath(support.TESTFN_UNENCODABLE)
4300-
self.sock.bind(path)
4312+
self.bind(self.sock, path)
43014313
self.addCleanup(support.unlink, path)
43024314
self.assertEqual(self.sock.getsockname(), path)
43034315

0 commit comments

Comments
 (0)