'Helper for testing L{IProcessTransport} write functionality.  This
method spawns a child process and gives C{write} a chance to write some
bytes to it.  It then verifies that the bytes were actually written to
it (by relying on the child process to echo them back).
@param write: A two-argument callable.  This is invoked with a process
transport and some bytes to write to it.'

def _writeTest(self, write):

    reactor = self.buildReactor()
    ended = Deferred()
    protocol = _ShutdownCallbackProcessProtocol(ended)
    bytesToSend = ('hello,    world' + networkString(os.linesep))
    program = 'import    sys\nsys.stdout.write(sys.stdin.readline())\n'
    def startup():
        transport = reactor.spawnProcess(protocol, pyExe, [pyExe, '-c', program])
        try:
            write(transport, bytesToSend)
        except:
            err(None, 'Unhandled    exception    while    writing')
            transport.signalProcess('KILL')
    reactor.callWhenRunning(startup)
    ended.addCallback((lambda ignored: reactor.stop()))
    self.runReactor(reactor)
    self.assertEqual(bytesToSend, ''.join(protocol.received[1]))
