Exemplo n.º 1
0
  def testStdinRedirect(self):
    waiter = process.Waiter(_JOB_STATE, _EXEC_OPTS)
    fd_state = process.FdState(_ERRFMT, _JOB_STATE)

    PATH = '_tmp/one-two.txt'
    # Write two lines
    with open(PATH, 'w') as f:
      f.write('one\ntwo\n')

    # Should get the first line twice, because Pop() closes it!

    r = redirect(Id.Redir_Less, runtime.NO_SPID, redir_loc.Fd(0),
                 redirect_arg.Path(PATH))

    fd_state.Push([r], waiter)
    line1, _ = builtin_misc.ReadLineFromStdin('\n')
    fd_state.Pop()

    fd_state.Push([r], waiter)
    line2, _ = builtin_misc.ReadLineFromStdin('\n')
    fd_state.Pop()

    # sys.stdin.readline() would erroneously return 'two' because of buffering.
    self.assertEqual('one', line1)
    self.assertEqual('one', line2)
Exemplo n.º 2
0
    def testStdinRedirect(self):
        PATH = '_tmp/one-two.txt'
        # Write two lines
        with open(PATH, 'w') as f:
            f.write('one\ntwo\n')

        # Should get the first line twice, because Pop() closes it!

        r = redirect(Id.Redir_Less, runtime.NO_SPID, redir_loc.Fd(0),
                     redirect_arg.Path(PATH))

        self.fd_state.Push([r], self.waiter)
        line1, _ = builtin_misc._ReadUntilDelim('\n')
        self.fd_state.Pop()

        self.fd_state.Push([r], self.waiter)
        line2, _ = builtin_misc._ReadUntilDelim('\n')
        self.fd_state.Pop()

        # sys.stdin.readline() would erroneously return 'two' because of buffering.
        self.assertEqual('one', line1)
        self.assertEqual('one', line2)