summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-09-08 09:47:54 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-09-08 09:47:54 (GMT)
commit7ba6b0f943ed9fc1782ec5813a07440d98d64554 (patch)
tree29de36b16e0491849881f7ede96df7929bc27f0f
parent88983500767e3bd042170552c12f9f5280dd4b3a (diff)
downloadcpython-7ba6b0f943ed9fc1782ec5813a07440d98d64554.zip
cpython-7ba6b0f943ed9fc1782ec5813a07440d98d64554.tar.gz
cpython-7ba6b0f943ed9fc1782ec5813a07440d98d64554.tar.bz2
Issue #18904: Improve os.get/set_inheritable() tests
-rw-r--r--Lib/test/test_os.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index d0dd364..aa48045 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -34,6 +34,10 @@ try:
import resource
except ImportError:
resource = None
+try:
+ import fcntl
+except ImportError:
+ fcntl = None
from test.script_helper import assert_python_ok
@@ -2300,19 +2304,37 @@ class CPUCountTests(unittest.TestCase):
class FDInheritanceTests(unittest.TestCase):
- def test_get_inheritable(self):
+ def test_get_set_inheritable(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)
- for inheritable in (False, True):
- os.set_inheritable(fd, inheritable)
- self.assertEqual(os.get_inheritable(fd), inheritable)
+ self.assertEqual(os.get_inheritable(fd), False)
- def test_set_inheritable(self):
- fd = os.open(__file__, os.O_RDONLY)
- self.addCleanup(os.close, fd)
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)
+
def test_open(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)