Kaydet (Commit) 4f7a36f8 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl

module is present (to record skipped tests)
üst 5da7e795
...@@ -2312,28 +2312,29 @@ class FDInheritanceTests(unittest.TestCase): ...@@ -2312,28 +2312,29 @@ class FDInheritanceTests(unittest.TestCase):
os.set_inheritable(fd, True) os.set_inheritable(fd, True)
self.assertEqual(os.get_inheritable(fd), True) self.assertEqual(os.get_inheritable(fd), True)
if fcntl: @unittest.skipIf(fcntl is None, "need fcntl")
def test_get_inheritable_cloexec(self): def test_get_inheritable_cloexec(self):
fd = os.open(__file__, os.O_RDONLY) fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd) self.addCleanup(os.close, fd)
self.assertEqual(os.get_inheritable(fd), False) self.assertEqual(os.get_inheritable(fd), False)
# clear FD_CLOEXEC flag # clear FD_CLOEXEC flag
flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags &= ~fcntl.FD_CLOEXEC flags &= ~fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags) 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): @unittest.skipIf(fcntl is None, "need fcntl")
fd = os.open(__file__, os.O_RDONLY) def test_set_inheritable_cloexec(self):
self.addCleanup(os.close, fd) fd = os.open(__file__, os.O_RDONLY)
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC, self.addCleanup(os.close, fd)
fcntl.FD_CLOEXEC) 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, os.set_inheritable(fd, True)
0) self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
0)
def test_open(self): def test_open(self):
fd = os.open(__file__, os.O_RDONLY) fd = os.open(__file__, os.O_RDONLY)
......
...@@ -4808,30 +4808,31 @@ class InheritanceTest(unittest.TestCase): ...@@ -4808,30 +4808,31 @@ class InheritanceTest(unittest.TestCase):
sock.set_inheritable(False) sock.set_inheritable(False)
self.assertEqual(sock.get_inheritable(), False) self.assertEqual(sock.get_inheritable(), False)
if fcntl: @unittest.skipIf(fcntl is None, "need fcntl")
def test_get_inheritable_cloexec(self): def test_get_inheritable_cloexec(self):
sock = socket.socket() sock = socket.socket()
with sock: with sock:
fd = sock.fileno() fd = sock.fileno()
self.assertEqual(sock.get_inheritable(), False) self.assertEqual(sock.get_inheritable(), False)
# clear FD_CLOEXEC flag # clear FD_CLOEXEC flag
flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags &= ~fcntl.FD_CLOEXEC flags &= ~fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags) 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): @unittest.skipIf(fcntl is None, "need fcntl")
sock = socket.socket() def test_set_inheritable_cloexec(self):
with sock: sock = socket.socket()
fd = sock.fileno() with sock:
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC, fd = sock.fileno()
fcntl.FD_CLOEXEC) 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, sock.set_inheritable(True)
0) self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
0)
@unittest.skipUnless(hasattr(socket, "socketpair"), @unittest.skipUnless(hasattr(socket, "socketpair"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment