summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2023-03-04 14:24:08 (GMT)
committerGitHub <noreply@github.com>2023-03-04 14:24:08 (GMT)
commitc2bd55d26f8eb2850eb9f9026b5d7f0ed1420b65 (patch)
tree3ee28c21d2a1654ac64cbbf8c47cfa4e5401f296 /Lib
parent705487c6557c3d8866622b4d32528bf7fc2e4204 (diff)
downloadcpython-c2bd55d26f8eb2850eb9f9026b5d7f0ed1420b65.zip
cpython-c2bd55d26f8eb2850eb9f9026b5d7f0ed1420b65.tar.gz
cpython-c2bd55d26f8eb2850eb9f9026b5d7f0ed1420b65.tar.bz2
gh-102179: Fix `os.dup2` error reporting for negative fds (#102180)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index deea207..792794c 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2221,6 +2221,26 @@ class TestInvalidFD(unittest.TestCase):
def test_dup2(self):
self.check(os.dup2, 20)
+ @unittest.skipUnless(hasattr(os, 'dup2'), 'test needs os.dup2()')
+ @unittest.skipIf(
+ support.is_emscripten,
+ "dup2() with negative fds is broken on Emscripten (see gh-102179)"
+ )
+ def test_dup2_negative_fd(self):
+ valid_fd = os.open(__file__, os.O_RDONLY)
+ self.addCleanup(os.close, valid_fd)
+ fds = [
+ valid_fd,
+ -1,
+ -2**31,
+ ]
+ for fd, fd2 in itertools.product(fds, repeat=2):
+ if fd != fd2:
+ with self.subTest(fd=fd, fd2=fd2):
+ with self.assertRaises(OSError) as ctx:
+ os.dup2(fd, fd2)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
@unittest.skipUnless(hasattr(os, 'fchmod'), 'test needs os.fchmod()')
def test_fchmod(self):
self.check(os.fchmod, 0)