MCPcopy Index your code
hub / github.com/python/cpython / check_close_std_fds

Method check_close_std_fds

Lib/test/test_subprocess.py:2657–2680  ·  view source on GitHub ↗
(self, fds)

Source from the content-addressed store, hash-verified

2655 os.close(saved)
2656
2657 def check_close_std_fds(self, fds):
2658 # Issue #9905: test that subprocess pipes still work properly with
2659 # some standard fds closed
2660 stdin = 0
2661 saved_fds = self._save_fds(fds)
2662 for fd, saved, inheritable in saved_fds:
2663 if fd == 0:
2664 stdin = saved
2665 break
2666 try:
2667 for fd in fds:
2668 os.close(fd)
2669 out, err = subprocess.Popen([sys.executable, "-c",
2670 'import sys;'
2671 'sys.stdout.write("apple");'
2672 'sys.stdout.flush();'
2673 'sys.stderr.write("orange")'],
2674 stdin=stdin,
2675 stdout=subprocess.PIPE,
2676 stderr=subprocess.PIPE).communicate()
2677 self.assertEqual(out, b'apple')
2678 self.assertEqual(err, b'orange')
2679 finally:
2680 self._restore_fds(saved_fds)
2681
2682 def test_close_fd_0(self):
2683 self.check_close_std_fds([0])

Callers 7

test_close_fd_0Method · 0.95
test_close_fd_1Method · 0.95
test_close_fd_2Method · 0.95
test_close_fds_0_1Method · 0.95
test_close_fds_0_2Method · 0.95
test_close_fds_1_2Method · 0.95
test_close_fds_0_1_2Method · 0.95

Calls 5

_save_fdsMethod · 0.95
_restore_fdsMethod · 0.95
closeMethod · 0.45
communicateMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected