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

Method test__copy_to_each

Lib/test/test_pty.py:388–416  ·  view source on GitHub ↗

Test the normal data case on both master_fd and stdin.

(self)

Source from the content-addressed store, hash-verified

386 self.tcsetattr_mode_setting = mode
387
388 def test__copy_to_each(self):
389 """Test the normal data case on both master_fd and stdin."""
390 read_from_stdout_fd, mock_stdout_fd = self._pipe()
391 pty.STDOUT_FILENO = mock_stdout_fd
392 mock_stdin_fd, write_to_stdin_fd = self._pipe()
393 pty.STDIN_FILENO = mock_stdin_fd
394 socketpair = self._socketpair()
395 masters = [s.fileno() for s in socketpair]
396
397 # Feed data. Smaller than PIPEBUF. These writes will not block.
398 write_all(masters[1], b'from master')
399 write_all(write_to_stdin_fd, b'from stdin')
400
401 # Expect three select calls, the last one will cause IndexError
402 pty.select = self._mock_select
403 self.select_input.append(([mock_stdin_fd, masters[0]], [], []))
404 self.select_output.append(([mock_stdin_fd, masters[0]], [], []))
405 self.select_input.append(([mock_stdin_fd, masters[0]], [mock_stdout_fd, masters[0]], []))
406 self.select_output.append(([], [mock_stdout_fd, masters[0]], []))
407 self.select_input.append(([mock_stdin_fd, masters[0]], [], []))
408
409 with self.assertRaises(IndexError):
410 pty._copy(masters[0])
411
412 # Test that the right data went to the right places.
413 rfds = select.select([read_from_stdout_fd, masters[1]], [], [], 0)[0]
414 self.assertEqual([read_from_stdout_fd, masters[1]], rfds)
415 self.assertEqual(os.read(read_from_stdout_fd, 20), b'from master')
416 self.assertEqual(os.read(masters[1], 20), b'from stdin')
417
418 def test__restore_tty_mode_normal_return(self):
419 """Test that spawn resets the tty mode no when _copy returns normally."""

Callers

nothing calls this directly

Calls 10

_pipeMethod · 0.95
_socketpairMethod · 0.95
write_allFunction · 0.85
filenoMethod · 0.45
appendMethod · 0.45
assertRaisesMethod · 0.45
_copyMethod · 0.45
selectMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected