mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-102179: Fix os.dup2
error reporting for negative fds (#102180)
This commit is contained in:
parent
705487c655
commit
c2bd55d26f
3 changed files with 21 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue