def main(): """ Main function to be run if __name__ == "__main__". """ config = WorkerOptions() config.parseOptions() from twisted.trial._dist.worker import WorkerProtocol workerProtocol = WorkerProtocol(config['force-gc']) protocolIn = os.fdopen(_WORKER_AMP_STDIN) protocolOut = os.fdopen(_WORKER_AMP_STDOUT, 'w') workerProtocol.makeConnection(FileWrapper(protocolOut)) observer = WorkerLogObserver(workerProtocol) startLoggingWithObserver(observer.emit, False) while True: try: r = protocolIn.read(1) except IOError, e: if e.args[0] == errno.EINTR: sys.exc_clear() continue else: raise if r == '': break else: workerProtocol.dataReceived(r) protocolOut.flush() sys.stdout.flush() sys.stderr.flush()
def main(_fdopen=os.fdopen): """ Main function to be run if __name__ == "__main__". @param _fdopen: If specified, the function to use in place of C{os.fdopen}. @param _fdopen: C{callable} """ config = WorkerOptions() config.parseOptions() from twisted.trial._dist.worker import WorkerProtocol workerProtocol = WorkerProtocol(config['force-gc']) protocolIn = _fdopen(_WORKER_AMP_STDIN) protocolOut = _fdopen(_WORKER_AMP_STDOUT, 'w') workerProtocol.makeConnection(FileWrapper(protocolOut)) observer = WorkerLogObserver(workerProtocol) startLoggingWithObserver(observer.emit, False) while True: try: r = protocolIn.read(1) if isinstance(r, unicode): r = r.encode("utf-8") except IOError as e: if e.args[0] == errno.EINTR: if sys.version_info < (3, 0): sys.exc_clear() continue else: raise if r == b'': break else: workerProtocol.dataReceived(r) protocolOut.flush() sys.stdout.flush() sys.stderr.flush() if config.tracer: sys.settrace(None) results = config.tracer.results() results.write_results(show_missing=True, summary=False, coverdir=config.coverdir().path)
def setUp(self): """ Build an L{WorkerOptions} object to be used in the tests. """ self.options = WorkerOptions()