'Processes spawned with spawnProcess() close all extraneous file
descriptors in the parent.  They do have a stdin, stdout, and stderr
open.'

@onlyOnPOSIX
def test_openFileDescriptors(self):

    source = networkString("\nimport    sys\nsys.path.insert(0,    '{0}')\nfrom    twisted.internet    import    process\nsys.stdout.write(repr(process._listOpenFDs()))\nsys.stdout.flush()".format(twistedRoot.path))
    (r, w) = os.pipe()
    self.addCleanup(os.close, r)
    self.addCleanup(os.close, w)
    fudgeFactor = 17
    unlikelyFD = (resource.getrlimit(resource.RLIMIT_NOFILE)[0] - fudgeFactor)
    os.dup2(w, unlikelyFD)
    self.addCleanup(os.close, unlikelyFD)
    output = io.BytesIO()
    class GatheringProtocol(ProcessProtocol, ):
        outReceived = output.write
        def processEnded(self, reason):
            reactor.stop()
    reactor = self.buildReactor()
    reactor.callWhenRunning(reactor.spawnProcess, GatheringProtocol(), pyExe, [pyExe, '-Wignore', '-c', source], usePTY=self.usePTY)
    self.runReactor(reactor)
    reportedChildFDs = set(eval(output.getvalue()))
    stdFDs = [0, 1, 2]
    self.assertEqual(reportedChildFDs.intersection(set((stdFDs + [unlikelyFD]))), set(stdFDs))
