gh-102179: Fix os.dup2 error reporting for negative fds (GH-102180)

(cherry picked from commit c2bd55d26f)

Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
This commit is contained in:
Miss Islington (bot) 2023-03-04 06:55:02 -08:00 committed by GitHub
parent 06a3bb8c94
commit cc6ce90206
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View file

@ -2176,6 +2176,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)