[Python-checkins] cpython: Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
victor.stinner
python-checkins at python.org
Sun Sep 8 14:14:53 CEST 2013
http://hg.python.org/cpython/rev/aea58e1cae75
changeset: 85624:aea58e1cae75
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Sep 08 14:14:38 2013 +0200
summary:
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
module is present (to record skipped tests)
files:
Lib/test/test_os.py | 37 +++++++++++----------
Lib/test/test_socket.py | 49 ++++++++++++++--------------
2 files changed, 44 insertions(+), 42 deletions(-)
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2312,28 +2312,29 @@
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)
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -4808,30 +4808,31 @@
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"),
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list