summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorcptpcrd <31829097+cptpcrd@users.noreply.github.com>2021-01-21 10:46:53 (GMT)
committerGitHub <noreply@github.com>2021-01-21 10:46:53 (GMT)
commit844ec0ba6606b60a59b7da82c54c1e646424259c (patch)
treef1643651fd0ab766ac4cb1f88e060ec1d9e995ce /Lib/test
parentebb2f26cd8b7c0b4919e994a8e62b6e709597939 (diff)
downloadcpython-844ec0ba6606b60a59b7da82c54c1e646424259c.zip
cpython-844ec0ba6606b60a59b7da82c54c1e646424259c.tar.gz
cpython-844ec0ba6606b60a59b7da82c54c1e646424259c.tar.bz2
bpo-42780: Fix set_inheritable() for O_PATH file descriptors on Linux (GH-24172) (GH-24277)
(cherry picked from commit 7dc71c425cf6aa6a4070a418dce5d95ca435c79f)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 2a4ae15..5302b1c 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -3513,6 +3513,33 @@ class FDInheritanceTests(unittest.TestCase):
self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC,
0)
+ @unittest.skipUnless(hasattr(os, 'O_PATH'), "need os.O_PATH")
+ def test_get_set_inheritable_o_path(self):
+ fd = os.open(__file__, os.O_PATH)
+ self.addCleanup(os.close, fd)
+ self.assertEqual(os.get_inheritable(fd), False)
+
+ os.set_inheritable(fd, True)
+ self.assertEqual(os.get_inheritable(fd), True)
+
+ os.set_inheritable(fd, False)
+ self.assertEqual(os.get_inheritable(fd), False)
+
+ def test_get_set_inheritable_badf(self):
+ fd = support.make_bad_fd()
+
+ with self.assertRaises(OSError) as ctx:
+ os.get_inheritable(fd)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
+ with self.assertRaises(OSError) as ctx:
+ os.set_inheritable(fd, True)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
+ with self.assertRaises(OSError) as ctx:
+ os.set_inheritable(fd, False)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
def test_open(self):
fd = os.open(__file__, os.O_RDONLY)
self.addCleanup(os.close, fd)