diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-03-04 15:27:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-04 15:27:32 (GMT) |
commit | 925ebfbfd22ac2ba3315ff427b9739d1e1907664 (patch) | |
tree | d100b3b3e65fc2b108bce9cf06fc63b2786bc9bc /Lib/test | |
parent | fe36778968a0fdddada282fbd7e28e8ccd0debe0 (diff) | |
download | cpython-925ebfbfd22ac2ba3315ff427b9739d1e1907664.zip cpython-925ebfbfd22ac2ba3315ff427b9739d1e1907664.tar.gz cpython-925ebfbfd22ac2ba3315ff427b9739d1e1907664.tar.bz2 |
[3.10] gh-102179: Fix `os.dup2` error reporting for negative fds (GH-102180) (#102419)
* gh-102179: Fix `os.dup2` error reporting for negative fds (GH-102180)
(cherry picked from commit c2bd55d26f8eb2850eb9f9026b5d7f0ed1420b65)
Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_os.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 1243b57..6b443c4 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -2143,6 +2143,22 @@ class TestInvalidFD(unittest.TestCase): def test_dup2(self): self.check(os.dup2, 20) + @unittest.skipUnless(hasattr(os, 'dup2'), 'test needs os.dup2()') + 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) |