mirror of
https://github.com/python/cpython.git
synced 2025-10-20 05:41:23 +00:00
Fix ResourceWarnings in test_pty
This commit is contained in:
parent
5461558d1a
commit
697ce5560f
1 changed files with 5 additions and 3 deletions
|
@ -215,7 +215,7 @@ class SmallPtyTests(unittest.TestCase):
|
||||||
for fd in self.fds:
|
for fd in self.fds:
|
||||||
try:
|
try:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _pipe(self):
|
def _pipe(self):
|
||||||
|
@ -235,8 +235,9 @@ class SmallPtyTests(unittest.TestCase):
|
||||||
mock_stdin_fd, write_to_stdin_fd = self._pipe()
|
mock_stdin_fd, write_to_stdin_fd = self._pipe()
|
||||||
pty.STDIN_FILENO = mock_stdin_fd
|
pty.STDIN_FILENO = mock_stdin_fd
|
||||||
socketpair = socket.socketpair()
|
socketpair = socket.socketpair()
|
||||||
|
for s in socketpair:
|
||||||
|
self.addCleanup(s.close)
|
||||||
masters = [s.fileno() for s in socketpair]
|
masters = [s.fileno() for s in socketpair]
|
||||||
self.fds.extend(masters)
|
|
||||||
|
|
||||||
# Feed data. Smaller than PIPEBUF. These writes will not block.
|
# Feed data. Smaller than PIPEBUF. These writes will not block.
|
||||||
os.write(masters[1], b'from master')
|
os.write(masters[1], b'from master')
|
||||||
|
@ -264,8 +265,9 @@ class SmallPtyTests(unittest.TestCase):
|
||||||
mock_stdin_fd, write_to_stdin_fd = self._pipe()
|
mock_stdin_fd, write_to_stdin_fd = self._pipe()
|
||||||
pty.STDIN_FILENO = mock_stdin_fd
|
pty.STDIN_FILENO = mock_stdin_fd
|
||||||
socketpair = socket.socketpair()
|
socketpair = socket.socketpair()
|
||||||
|
for s in socketpair:
|
||||||
|
self.addCleanup(s.close)
|
||||||
masters = [s.fileno() for s in socketpair]
|
masters = [s.fileno() for s in socketpair]
|
||||||
self.fds.extend(masters)
|
|
||||||
|
|
||||||
os.close(masters[1])
|
os.close(masters[1])
|
||||||
socketpair[1].close()
|
socketpair[1].close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue