class WorkerOptionsTests(TestCase): """ Tests for L{WorkerOptions}. """ def setUp(self): """ Build an L{WorkerOptions} object to be used in the tests. """ self.options = WorkerOptions() def test_standardOptions(self): """ L{WorkerOptions} supports a subset of standard options supported by trial. """ self.addCleanup(sys.setrecursionlimit, sys.getrecursionlimit()) if gc.isenabled(): self.addCleanup(gc.enable) gc.enable() self.options.parseOptions(["--recursionlimit", "2000", "--disablegc"]) self.assertEqual(2000, sys.getrecursionlimit()) self.assertFalse(gc.isenabled()) def test_coverage(self): """ L{WorkerOptions.coverdir} returns the C{coverage} child directory of the current directory to be used for storing coverage data. """ self.assertEqual(os.path.realpath(os.path.join(os.getcwd(), "coverage")), self.options.coverdir().path)
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()
class WorkerOptionsTestCase(TestCase): """ Tests for L{WorkerOptions}. """ def setUp(self): """ Build an L{WorkerOptions} object to be used in the tests. """ self.options = WorkerOptions() def test_standardOptions(self): """ L{WorkerOptions} supports a subset of standard options supported by trial. """ self.addCleanup(sys.setrecursionlimit, sys.getrecursionlimit()) if gc.isenabled(): self.addCleanup(gc.enable) gc.enable() self.options.parseOptions(["--recursionlimit", "2000", "--disablegc"]) self.assertEqual(2000, sys.getrecursionlimit()) self.assertFalse(gc.isenabled()) def test_coverage(self): """ L{WorkerOptions.coverdir} returns the C{coverage} child directory of the current directory to be used for storing coverage data. """ self.assertEqual( os.path.realpath(os.path.join(os.getcwd(), "coverage")), self.options.coverdir().path)
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()