(self)
| 3724 | self.assertEqual(rc, 47) |
| 3725 | |
| 3726 | def test_close_fds_with_stdio(self): |
| 3727 | import msvcrt |
| 3728 | |
| 3729 | fds = os.pipe() |
| 3730 | self.addCleanup(os.close, fds[0]) |
| 3731 | self.addCleanup(os.close, fds[1]) |
| 3732 | |
| 3733 | handles = [] |
| 3734 | for fd in fds: |
| 3735 | os.set_inheritable(fd, True) |
| 3736 | handles.append(msvcrt.get_osfhandle(fd)) |
| 3737 | |
| 3738 | p = subprocess.Popen([sys.executable, "-c", |
| 3739 | "import msvcrt; print(msvcrt.open_osfhandle({}, 0))".format(handles[0])], |
| 3740 | stdout=subprocess.PIPE, close_fds=False) |
| 3741 | stdout, stderr = p.communicate() |
| 3742 | self.assertEqual(p.returncode, 0) |
| 3743 | int(stdout.strip()) # Check that stdout is an integer |
| 3744 | |
| 3745 | p = subprocess.Popen([sys.executable, "-c", |
| 3746 | "import msvcrt; print(msvcrt.open_osfhandle({}, 0))".format(handles[0])], |
| 3747 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) |
| 3748 | stdout, stderr = p.communicate() |
| 3749 | self.assertEqual(p.returncode, 1) |
| 3750 | self.assertIn(b"OSError", stderr) |
| 3751 | |
| 3752 | # The same as the previous call, but with an empty handle_list |
| 3753 | handle_list = [] |
| 3754 | startupinfo = subprocess.STARTUPINFO() |
| 3755 | startupinfo.lpAttributeList = {"handle_list": handle_list} |
| 3756 | p = subprocess.Popen([sys.executable, "-c", |
| 3757 | "import msvcrt; print(msvcrt.open_osfhandle({}, 0))".format(handles[0])], |
| 3758 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 3759 | startupinfo=startupinfo, close_fds=True) |
| 3760 | stdout, stderr = p.communicate() |
| 3761 | self.assertEqual(p.returncode, 1) |
| 3762 | self.assertIn(b"OSError", stderr) |
| 3763 | |
| 3764 | # Check for a warning due to using handle_list and close_fds=False |
| 3765 | with warnings_helper.check_warnings((".*overriding close_fds", |
| 3766 | RuntimeWarning)): |
| 3767 | startupinfo = subprocess.STARTUPINFO() |
| 3768 | startupinfo.lpAttributeList = {"handle_list": handles[:]} |
| 3769 | p = subprocess.Popen([sys.executable, "-c", |
| 3770 | "import msvcrt; print(msvcrt.open_osfhandle({}, 0))".format(handles[0])], |
| 3771 | stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 3772 | startupinfo=startupinfo, close_fds=False) |
| 3773 | stdout, stderr = p.communicate() |
| 3774 | self.assertEqual(p.returncode, 0) |
| 3775 | |
| 3776 | def test_empty_attribute_list(self): |
| 3777 | startupinfo = subprocess.STARTUPINFO() |
nothing calls this directly
no test coverage detected