'The C{reason} argument passed to L{IProcessProtocol.processExited} is a
L{ProcessTerminated} instance if the child process exits with a signal.'

def test_processExitedWithSignal(self):

    sigName = 'TERM'
    sigNum = getattr(signal, ('SIG' + sigName))
    exited = Deferred()
    source = "import    sys\nsys.stdout.write('x')\nsys.stdout.flush()\nsys.stdin.read()\n"
    class Exiter(ProcessProtocol, ):
        def childDataReceived(self, fd, data):
            msg(('childDataReceived(%d,    %r)' % (fd, data)))
            self.transport.signalProcess(sigName)
        def childConnectionLost(self, fd):
            msg(('childConnectionLost(%d)' % (fd,)))
        def processExited(self, reason):
            msg(('processExited(%r)' % (reason,)))
            exited.callback([reason])
        def processEnded(self, reason):
            msg(('processEnded(%r)' % (reason,)))
    reactor = self.buildReactor()
    reactor.callWhenRunning(reactor.spawnProcess, Exiter(), pyExe, [pyExe, '-c', source], usePTY=self.usePTY)
    def cbExited(args):
        (failure,) = args
        failure.trap(ProcessTerminated)
        err = failure.value
        if platform.isWindows():
            self.assertIsNone(err.signal)
            self.assertEqual(err.exitCode, 1)
        else:
            self.assertEqual(err.signal, sigNum)
            self.assertIsNone(err.exitCode)
    exited.addCallback(cbExited)
    exited.addErrback(err)
    exited.addCallback((lambda ign: reactor.stop()))
    self.runReactor(reactor)
