]> granicus.if.org Git - python/commitdiff
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 8 Sep 2013 12:14:38 +0000 (14:14 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 8 Sep 2013 12:14:38 +0000 (14:14 +0200)
module is present (to record skipped tests)

Lib/test/test_os.py
Lib/test/test_socket.py

index aa48045a3036681daedff29b4413acf8d2e36f76..39b0e80125b9edfeec4bea9ad1efdf8b421f40da 100644 (file)
@@ -2312,28 +2312,29 @@ class FDInheritanceTests(unittest.TestCase):
         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)
-
-            # 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)
-
-        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)
+    @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)
+
+        self.assertEqual(os.get_inheritable(fd), True)
+
+    @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)
 
     def test_open(self):
         fd = os.open(__file__, os.O_RDONLY)
index fc478b6a8731ece92e03c57e9dc6ea4b604016d1..490f776d21e0605640444a3b7a08ee7bab3f43c8 100644 (file)
@@ -4808,30 +4808,31 @@ class InheritanceTest(unittest.TestCase):
             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)
-
-                # 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)
-
-        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)
+    @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)
+
+            self.assertEqual(sock.get_inheritable(), True)
+
+    @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)
 
 
     @unittest.skipUnless(hasattr(socket, "socketpair"),