mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
module is present (to record skipped tests)
This commit is contained in:
parent
5da7e7959e
commit
4f7a36f84f
2 changed files with 40 additions and 38 deletions
|
|
@ -2312,28 +2312,29 @@ def test_get_set_inheritable(self):
|
|||
os.set_inheritable(fd, True)
|
||||
self.assertEqual(os.get_inheritable(fd), True)
|
||||
|
||||
if fcntl:
|
||||
def test_get_inheritable_cloexec(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
self.addCleanup(os.close, fd)
|
||||
self.assertEqual(os.get_inheritable(fd), False)
|
||||
@unittest.skipIf(fcntl is None, "need fcntl")
|
||||
def test_get_inheritable_cloexec(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
self.addCleanup(os.close, fd)
|
||||
self.assertEqual(os.get_inheritable(fd), False)
|
||||
|
||||
# clear FD_CLOEXEC flag
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||
flags &= ~fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||
# clear FD_CLOEXEC flag
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||
flags &= ~fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||
|
||||
self.assertEqual(os.get_inheritable(fd), True)
|
||||
self.assertEqual(os.get_inheritable(fd), True)
|
||||
|
||||
def test_set_inheritable_cloexec(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
self.addCleanup(os.close, fd)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
fcntl.FD_CLOEXEC)
|
||||
@unittest.skipIf(fcntl is None, "need fcntl")
|
||||
def test_set_inheritable_cloexec(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
self.addCleanup(os.close, fd)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
fcntl.FD_CLOEXEC)
|
||||
|
||||
os.set_inheritable(fd, True)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
0)
|
||||
os.set_inheritable(fd, True)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
0)
|
||||
|
||||
def test_open(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
|
|
|
|||
|
|
@ -4808,30 +4808,31 @@ def test_set_inheritable(self):
|
|||
sock.set_inheritable(False)
|
||||
self.assertEqual(sock.get_inheritable(), False)
|
||||
|
||||
if fcntl:
|
||||
def test_get_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(sock.get_inheritable(), False)
|
||||
@unittest.skipIf(fcntl is None, "need fcntl")
|
||||
def test_get_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(sock.get_inheritable(), False)
|
||||
|
||||
# clear FD_CLOEXEC flag
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||
flags &= ~fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||
# clear FD_CLOEXEC flag
|
||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||
flags &= ~fcntl.FD_CLOEXEC
|
||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
||||
|
||||
self.assertEqual(sock.get_inheritable(), True)
|
||||
self.assertEqual(sock.get_inheritable(), True)
|
||||
|
||||
def test_set_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
fcntl.FD_CLOEXEC)
|
||||
@unittest.skipIf(fcntl is None, "need fcntl")
|
||||
def test_set_inheritable_cloexec(self):
|
||||
sock = socket.socket()
|
||||
with sock:
|
||||
fd = sock.fileno()
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
fcntl.FD_CLOEXEC)
|
||||
|
||||
sock.set_inheritable(True)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
0)
|
||||
sock.set_inheritable(True)
|
||||
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
|
||||
0)
|
||||
|
||||
|
||||
@unittest.skipUnless(hasattr(socket, "socketpair"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue