Exemplo n.º 1
0
 def setUp(self):
     TestCase.setUp(self)
     TestHelper.setUp(self)
     self.threadpool = FakeThreadPool()
     self.transaction = self.mocker.mock()
     self.transactor = Transactor(self.threadpool, self.transaction)
     self.function = self.mocker.mock()
Exemplo n.º 2
0
 def tearDown(self):
     if log.defaultObserver is not None:
         log.defaultObserver.start()
     TestCase.tearDown(self)
     # Trial should restore the handler itself, but doesn't.
     # See bug #3888 in Twisted tracker.
     signal.signal(signal.SIGINT, signal.default_int_handler)
Exemplo n.º 3
0
def compareEvents(
    test: unittest.TestCase,
    actualEvents: List[LogEvent],
    expectedEvents: List[LogEvent],
) -> None:
    """
    Compare two sequences of log events, examining only the the keys which are
    present in both.

    @param test: a test case doing the comparison
    @param actualEvents: A list of log events that were emitted by a logger.
    @param expectedEvents: A list of log events that were expected by a test.
    """
    if len(actualEvents) != len(expectedEvents):
        test.assertEqual(actualEvents, expectedEvents)
    allMergedKeys = set()

    for event in expectedEvents:
        allMergedKeys |= set(event.keys())

    def simplify(event: LogEvent) -> LogEvent:
        copy = event.copy()
        for key in event.keys():
            if key not in allMergedKeys:
                copy.pop(key)
        return copy

    simplifiedActual = [simplify(event) for event in actualEvents]
    test.assertEqual(simplifiedActual, expectedEvents)
Exemplo n.º 4
0
 def setUp(self):
     TestCase.setUp(self)
     TestHelper.setUp(self)
     self.threadpool = FakeThreadPool()
     self.transaction = self.mocker.mock()
     self.transactor = Transactor(self.threadpool, self.transaction)
     self.function = self.mocker.mock()
    def setUp(self):
        TestCase.setUp(self)

        test_upgrader = UpgradeDatabaseSchemaStep(None)
        self.upgradePath = test_upgrader.schemaLocation.child("old").child(POSTGRES_DIALECT)
        self.currentVersion = self._getSchemaVersion(test_upgrader.schemaLocation.child("current.sql"), "VERSION")

        self.store = yield theStoreBuilder.buildStore(
            self, {"push": StubNotifierFactory()}, enableJobProcessing=False
        )
Exemplo n.º 6
0
    def setUp(self):
        TestCase.setUp(self)

        test_upgrader = UpgradeDatabaseSchemaStep(None)
        self.upgradePath = test_upgrader.schemaLocation.child("old").child(
            POSTGRES_DIALECT)
        self.currentVersion = self._getSchemaVersion(
            test_upgrader.schemaLocation.child("current.sql"), "VERSION")

        self.store = yield theStoreBuilder.buildStore(
            self, {"push": StubNotifierFactory()}, enableJobProcessing=False)
Exemplo n.º 7
0
def savedJSONInvariants(testCase: TestCase, savedJSON: str) -> str:
    """
    Assert a few things about the result of L{eventAsJSON}, then return it.

    @param testCase: The L{TestCase} with which to perform the assertions.
    @param savedJSON: The result of L{eventAsJSON}.

    @return: C{savedJSON}

    @raise AssertionError: If any of the preconditions fail.
    """
    testCase.assertIsInstance(savedJSON, str)
    testCase.assertEqual(savedJSON.count("\n"), 0)
    return savedJSON
Exemplo n.º 8
0
    def test_runUsedDirectory(self):
        """
        L{DistTrialRunner} checks if the test directory is already locked, and
        if it is generates a name based on it.
        """

        class FakeReactorWithLock(FakeReactor):

            def spawnProcess(oself, worker, *args, **kwargs):
                self.assertEqual(os.path.abspath(worker._logDirectory),
                                 os.path.abspath(
                                     os.path.join(workingDirectory + "-1",
                                                  str(oself.spawnCount))))
                localLock = FilesystemLock(workingDirectory + "-1.lock")
                self.assertFalse(localLock.lock())
                oself.spawnCount += 1
                worker.makeConnection(FakeTransport())
                worker._ampProtocol.run = lambda *args: succeed(None)

        newDirectory = self.mktemp()
        os.mkdir(newDirectory)
        workingDirectory = os.path.join(newDirectory, "_trial_temp")
        lock = FilesystemLock(workingDirectory + ".lock")
        lock.lock()
        self.addCleanup(lock.unlock)
        self.runner._workingDirectory = workingDirectory

        fakeReactor = FakeReactorWithLock()
        suite = TrialSuite()
        for i in xrange(10):
            suite.addTest(TestCase())
        self.runner.run(suite, fakeReactor)
Exemplo n.º 9
0
    def childStore(self):
        """
        Create a store suitable for use in a child process, that is hooked up
        to the store that a parent test process is managing.
        """
        disableMemcacheForTest(TestCase())
        staticQuota = 3000
        attachmentRoot = (FilePath(self.sharedDBPath).child("attachments"))
        stubsvc = self.createService(lambda cf: Service())

        cp = ConnectionPool(
            stubsvc.produceConnection,
            maxConnections=1,
            dbtype=DatabaseType(DB_TYPE[0], DB_TYPE[1]),
        )
        # Attach the service to the running reactor.
        cp.startService()
        reactor.addSystemEventTrigger("before", "shutdown", cp.stopService)
        cds = CommonDataStore(cp.connection, {
            "push": StubNotifierFactory(),
        },
                              None,
                              attachmentRoot,
                              "",
                              quota=staticQuota)
        return cds
Exemplo n.º 10
0
    def test_runWaitForProcessesDeferreds(self):
        """
        L{DistTrialRunner} waits for the worker processes to stop when the
        reactor is stopping, and then unlocks the test directory, not trying to
        stop the reactor again.
        """
        workers = []
        workingDirectory = self.runner._workingDirectory

        fakeReactor = CountingReactor(workers)
        self.runner.run(TestCase(), fakeReactor)

        def check(ign):
            # Let the AMP deferreds fire
            return deferLater(reactor, 0, realCheck)

        def realCheck():
            localLock = FilesystemLock(workingDirectory + ".lock")
            self.assertTrue(localLock.lock())
            # Stop is not called, as it ought to have been called before
            self.assertEqual(0, fakeReactor.stopCount)

        self.assertEqual(list(fakeReactor.triggers.keys()), ["before"])
        self.assertEqual(list(fakeReactor.triggers["before"]), ["shutdown"])
        self.reap(workers)

        return gatherResults([
            maybeDeferred(f, *a, **kw)
            for f, a, kw in fakeReactor.triggers["before"]["shutdown"]
        ]).addCallback(check)
Exemplo n.º 11
0
 def test_minimalWorker(self):
     """
     L{DistTrialRunner} doesn't try to start more workers than the number of
     tests.
     """
     fakeReactor = FakeReactor()
     self.runner.run(TestCase(), fakeReactor)
     self.assertEqual(fakeReactor.runCount, 1)
     self.assertEqual(fakeReactor.spawnCount, 1)
Exemplo n.º 12
0
 def test_runUncleanWarnings(self):
     """
     Running with the C{unclean-warnings} option makes L{DistTrialRunner}
     uses the L{UncleanWarningsReporterWrapper}.
     """
     fakeReactor = FakeReactor()
     self.runner._uncleanWarnings = True
     result = self.runner.run(TestCase(), fakeReactor)
     self.assertIsInstance(result, DistReporter)
     self.assertIsInstance(result.original, UncleanWarningsReporterWrapper)
def test_middleware_wait():
    def download_func(spider, request):
        return request

    spider = spider_with_crawler()
    request = Request('http://example.com', meta={'wait_time': 1})
    # We send the request to all the downloader middlewares, including the delayed request middleware.
    manager = DownloaderMiddlewareManager.from_crawler(spider.crawler)
    downloaded = manager.download(download_func, request, spider)

    assert isinstance(downloaded, Deferred)

    # https://github.com/scrapy/scrapy/blob/28262d4b241744aa7c090702db9a89411e3bbf9a/tests/test_downloadermiddleware.py#L36
    results = []
    downloaded.addBoth(results.append)
    test = TestCase()
    test._wait(downloaded)

    assert len(results) == 1
    assert results[0].url == request.url
Exemplo n.º 14
0
 def test_run(self):
     """
     C{run} starts the reactor exactly once and spawns each of the workers
     exactly once.
     """
     fakeReactor = FakeReactor()
     suite = TrialSuite()
     for i in xrange(10):
         suite.addTest(TestCase())
     self.runner.run(suite, fakeReactor)
     self.assertEqual(fakeReactor.runCount, 1)
     self.assertEqual(fakeReactor.spawnCount, self.runner._workerNumber)
Exemplo n.º 15
0
    def test_minimalWorker(self):
        """
        L{DistTrialRunner} doesn't try to start more workers than the number of
        tests.
        """
        workers = []
        fakeReactor = CountingReactor(workers)
        self.addCleanup(self.reap, workers)

        self.runner.run(TestCase(), fakeReactor)
        self.assertEqual(fakeReactor.runCount, 1)
        self.assertEqual(fakeReactor.spawnCount, 1)
Exemplo n.º 16
0
class DistReporterTestCase(TestCase):
    """
    Tests for L{DistReporter}.
    """

    def setUp(self):
        self.stream = StringIO()
        self.distReporter = DistReporter(TreeReporter(self.stream))
        self.test = TestCase()


    def test_startSuccessStop(self):
        """
        Success output only gets sent to the stream after the test has stopped.
        """
        self.distReporter.startTest(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.addSuccess(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.stopTest(self.test)
        self.assertNotEqual(self.stream.getvalue(), "")


    def test_startErrorStop(self):
        """
        Error output only gets sent to the stream after the test has stopped.
        """
        self.distReporter.startTest(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.addError(self.test, "error")
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.stopTest(self.test)
        self.assertNotEqual(self.stream.getvalue(), "")


    def test_forwardedMethods(self):
        """
        Calling methods of L{DistReporter} add calls to the running queue of
        the test.
        """
        self.distReporter.startTest(self.test)
        self.distReporter.addFailure(self.test, "foo")
        self.distReporter.addError(self.test, "bar")
        self.distReporter.addSkip(self.test, "egg")
        self.distReporter.addUnexpectedSuccess(self.test, "spam")
        self.distReporter.addExpectedFailure(self.test, "err", "foo")
        self.assertEqual(len(self.distReporter.running[self.test.id()]), 6)
Exemplo n.º 17
0
class DistReporterTestCase(TestCase):
    """
    Tests for L{DistReporter}.
    """

    def setUp(self):
        self.stream = StringIO()
        self.distReporter = DistReporter(TreeReporter(self.stream))
        self.test = TestCase()


    def test_startSuccessStop(self):
        """
        Success output only gets sent to the stream after the test has stopped.
        """
        self.distReporter.startTest(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.addSuccess(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.stopTest(self.test)
        self.assertNotEqual(self.stream.getvalue(), "")


    def test_startErrorStop(self):
        """
        Error output only gets sent to the stream after the test has stopped.
        """
        self.distReporter.startTest(self.test)
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.addError(self.test, "error")
        self.assertEqual(self.stream.getvalue(), "")
        self.distReporter.stopTest(self.test)
        self.assertNotEqual(self.stream.getvalue(), "")


    def test_forwardedMethods(self):
        """
        Calling methods of L{DistReporter} add calls to the running queue of
        the test.
        """
        self.distReporter.startTest(self.test)
        self.distReporter.addFailure(self.test, "foo")
        self.distReporter.addError(self.test, "bar")
        self.distReporter.addSkip(self.test, "egg")
        self.distReporter.addUnexpectedSuccess(self.test, "spam")
        self.distReporter.addExpectedFailure(self.test, "err", "foo")
        self.assertEqual(len(self.distReporter.running[self.test.id()]), 6)
Exemplo n.º 18
0
    def test_runWaitForProcessesDeferreds(self):
        """
        L{DistTrialRunner} waits for the worker processes to stop when the
        reactor is stopping, and then unlocks the test directory, not trying to
        stop the reactor again.
        """
        functions = []
        workers = []

        class FakeReactorWithEvent(FakeReactor):

            def spawnProcess(self, worker, *args, **kwargs):
                worker.makeConnection(FakeTransport())
                workers.append(worker)

            def addSystemEventTrigger(oself, phase, event, function):
                self.assertEqual('before', phase)
                self.assertEqual('shutdown', event)
                functions.append(function)

        workingDirectory = self.runner._workingDirectory

        fakeReactor = FakeReactorWithEvent()
        self.runner.run(TestCase(), fakeReactor)

        def check(ign):
            # Let the AMP deferreds fire
            return deferLater(reactor, 0, realCheck)

        def realCheck():
            localLock = FilesystemLock(workingDirectory + ".lock")
            self.assertTrue(localLock.lock())
            # Stop is not called, as it ought to have been called before
            self.assertEqual(0, fakeReactor.stopCount)

        workers[0].processEnded(Failure(CONNECTION_DONE))
        return functions[0]().addCallback(check)
Exemplo n.º 19
0
 def __init__(self, *args, **kwargs):
     #self.system=
     self.server=SLServer("Test SLServer")
     TestCase.__init__(self, *args,**kwargs)
Exemplo n.º 20
0
 def __init__(self, methodName, fixtureDir, workingDir):
     self._methodName = methodName
     TestCase.__init__(self, methodName)
     self._fixtureDir = fixtureDir
     self._workingDir = workingDir
     self._envDir = None
Exemplo n.º 21
0
 def setUp(self):
     self.fakeAMProtocol = FakeAMProtocol()
     self.workerReporter = WorkerReporter(self.fakeAMProtocol)
     self.test = TestCase()
 def setUp(self):
     # We need to skip the immediate base class since we are creating our own
     # store in each test
     yield TestCase.setUp(self)
Exemplo n.º 23
0
 def __init__(self, *args, **kwargs):
     #self.system=
     self.dbOaf = db.Oaf("Test Bound Server", "skeleton")
     self.server=BoundSLOafServer(self.dbOaf)
     TestCase.__init__(self, *args,**kwargs)
Exemplo n.º 24
0
 def __init__(self, step_runner, step_registry, feature, scenario,
              feature_suite):
     FreshenTestCase.__init__(self, step_runner, step_registry, feature,
                              scenario, feature_suite)
     TestCase.__init__(self, scenario.name)
Exemplo n.º 25
0
 def __init__(self, *args, **kwargs):
     self.system = System("Test System Name")
     self.oaf = OafServer()
     TestCase.__init__(self, *args, **kwargs)
Exemplo n.º 26
0
 def tearDown(self):
     ResourcedTestCase.tearDown(self)
     TestCase.tearDown(self)
Exemplo n.º 27
0
                worker.makeConnection(FakeTransport())
                self.spawnCount += 1
                worker._ampProtocol.run = self.succeedingRun

            def succeedingRun(self, case, result):
                return succeed(None)

            def addSystemEventTrigger(oself, phase, event, function):
                self.assertEqual('before', phase)
                self.assertEqual('shutdown', event)
                functions.append(function)

        workingDirectory = self.runner._workingDirectory

        fakeReactor = FakeReactorWithSuccess()
        self.runner.run(TestCase(), fakeReactor)

        def check():
            localLock = FilesystemLock(workingDirectory + ".lock")
            self.assertTrue(localLock.lock())
            self.assertEqual(1, fakeReactor.stopCount)
            # We don't wait for the process deferreds here, so nothign is
            # returned by the function before shutdown
            self.assertIdentical(None, functions[0]())

        return deferLater(reactor, 0, check)


    def test_runWaitForProcessesDeferreds(self):
        """
        L{DistTrialRunner} waits for the worker processes to stop when the
Exemplo n.º 28
0
 def setUp(self):
     self.stream = StringIO()
     self.distReporter = DistReporter(TreeReporter(self.stream))
     self.test = TestCase()
Exemplo n.º 29
0
    def setUp(self):
        TestCase.setUp(self)

        self.store = yield self.testStoreBuilder.buildStore(
            self, {"push": StubNotifierFactory()}, enableJobProcessing=False
        )
Exemplo n.º 30
0
    def setUp(self):
        TestCase.setUp(self)

        self.group = Group("GID")
Exemplo n.º 31
0
 def __init__(self, methodName='runTest'):
     TrialTestCase.__init__(self, methodName)
     self.testMethod = getattr(self, methodName)
Exemplo n.º 32
0
    def setUp(self):
        TestCase.setUp(self)

        self.group = Group('GID')
Exemplo n.º 33
0
 def setUp(self):
     # We need to skip the immediate base class since we are creating our own
     # store in each test
     yield TestCase.setUp(self)
Exemplo n.º 34
0
 def setUp(self):
     TestCase.setUp(self)
     # Define a GID group with custom messaging credentials
     self.group = Group('GID')
Exemplo n.º 35
0
 def __init__(self, step_runner, step_registry,
              feature, scenario, feature_suite, position, feature_path):
     FreshenTestCase.__init__(self, step_runner, step_registry,
                              feature, scenario, feature_suite, position, feature_path)
     TestCase.__init__(self, scenario.name)
Exemplo n.º 36
0
 def setUp(self):
     ResourcedTestCase.setUp(self)
     TestCase.setUp(self)
Exemplo n.º 37
0
Arquivo: base.py Projeto: lzimm/360io
 def setUp(self):
     TestCase.setUp(self)
     self._stash_environ()
Exemplo n.º 38
0
 def setUp(self) -> None:
     self.stream = StringIO()
     self.distReporter = DistReporter(TreeReporter(self.stream))
     self.test = TestCase()
Exemplo n.º 39
0
 def __init__(self, step_runner, step_registry,
              feature, scenario, feature_suite):
     FresherTestCase.__init__(self, step_runner, step_registry,
                              feature, scenario, feature_suite)
     TestCase.__init__(self, scenario.name)
Exemplo n.º 40
0
 def __init__(self, methodName='runTest'):
     TrialTestCase.__init__(self, methodName)
     self.testMethod = getattr(self, methodName)
Exemplo n.º 41
0
        class CountingReactorWithSuccess(CountingReactor):
            def spawnProcess(self, worker, *args, **kwargs):
                self._workers.append(worker)
                worker.makeConnection(FakeTransport())
                self.spawnCount += 1
                worker._ampProtocol.run = self.succeedingRun

            def succeedingRun(self, case, result):
                return succeed(None)

        workingDirectory = self.runner._workingDirectory

        workers = []
        fakeReactor = CountingReactorWithSuccess(workers)

        self.runner.run(TestCase(), fakeReactor)

        def check():
            localLock = FilesystemLock(workingDirectory + ".lock")
            self.assertTrue(localLock.lock())
            self.assertEqual(1, fakeReactor.stopCount)

        self.assertEqual(list(fakeReactor.triggers.keys()), ["before"])
        self.assertEqual(list(fakeReactor.triggers["before"]), ["shutdown"])
        self.reap(workers)

        return deferLater(reactor, 0, check)

    def test_runWaitForProcessesDeferreds(self):
        """
        L{DistTrialRunner} waits for the worker processes to stop when the
Exemplo n.º 42
0
    def setUp(self):
        TestCase.setUp(self)

        self.store = yield self.testStoreBuilder.buildStore(
            self, {"push": StubNotifierFactory()}, enableJobProcessing=False
        )
Exemplo n.º 43
0
class DistTrialRunnerTestCase(TestCase):
    """
    Tests for L{DistTrialRunner}.
    """

    def setUp(self):
        """
        Create a runner for testing.
        """
        self.runner = DistTrialRunner(TreeReporter, 4, [],
                                      workingDirectory=self.mktemp())
        self.runner._stream = StringIO()


    def test_writeResults(self):
        """
        L{DistTrialRunner.writeResults} writes to the stream specified in the
        init.
        """
        stringIO = StringIO()
        result = DistReporter(Reporter(stringIO))
        self.runner.writeResults(result)
        self.assertTrue(stringIO.tell() > 0)


    def test_createLocalWorkers(self):
        """
        C{createLocalWorkers} iterates the list of protocols and create one
        L{LocalWorker} for each.
        """
        protocols = [object() for x in xrange(4)]
        workers = self.runner.createLocalWorkers(protocols, "path")
        for s in workers:
            self.assertIsInstance(s, LocalWorker)
        self.assertEqual(4, len(workers))


    def test_launchWorkerProcesses(self):
        """
        Given a C{spawnProcess} function, C{launchWorkerProcess} launches a
        python process with a existing path as its argument.
        """
        protocols = [ProcessProtocol() for i in range(4)]
        arguments = []
        environment = {}

        def fakeSpawnProcess(processProtocol, executable, args=(), env={},
                             path=None, uid=None, gid=None, usePTY=0,
                             childFDs=None):
            arguments.append(executable)
            arguments.extend(args)
            environment.update(env)

        self.runner.launchWorkerProcesses(
            fakeSpawnProcess, protocols, ["foo"])
        self.assertEqual(arguments[0], arguments[1])
        self.assertTrue(os.path.exists(arguments[2]))
        self.assertEqual("foo", arguments[3])
        self.assertEqual(os.pathsep.join(sys.path),
                         environment["TRIAL_PYTHONPATH"])


    def test_run(self):
        """
        C{run} starts the reactor exactly once and spawns each of the workers
        exactly once.
        """
        fakeReactor = FakeReactor()
        suite = TrialSuite()
        for i in xrange(10):
            suite.addTest(TestCase())
        self.runner.run(suite, fakeReactor)
        self.assertEqual(fakeReactor.runCount, 1)
        self.assertEqual(fakeReactor.spawnCount, self.runner._workerNumber)


    def test_runUsedDirectory(self):
        """
        L{DistTrialRunner} checks if the test directory is already locked, and
        if it is generates a name based on it.
        """

        class FakeReactorWithLock(FakeReactor):

            def spawnProcess(oself, worker, *args, **kwargs):
                self.assertEqual(os.path.abspath(worker._logDirectory),
                                 os.path.abspath(
                                     os.path.join(workingDirectory + "-1",
                                                  str(oself.spawnCount))))
                localLock = FilesystemLock(workingDirectory + "-1.lock")
                self.assertFalse(localLock.lock())
                oself.spawnCount += 1
                worker.makeConnection(FakeTransport())
                worker._ampProtocol.run = lambda *args: succeed(None)

        newDirectory = self.mktemp()
        os.mkdir(newDirectory)
        workingDirectory = os.path.join(newDirectory, "_trial_temp")
        lock = FilesystemLock(workingDirectory + ".lock")
        lock.lock()
        self.addCleanup(lock.unlock)
        self.runner._workingDirectory = workingDirectory

        fakeReactor = FakeReactorWithLock()
        suite = TrialSuite()
        for i in xrange(10):
            suite.addTest(TestCase())
        self.runner.run(suite, fakeReactor)


    def test_minimalWorker(self):
        """
        L{DistTrialRunner} doesn't try to start more workers than the number of
        tests.
        """
        fakeReactor = FakeReactor()
        self.runner.run(TestCase(), fakeReactor)
        self.assertEqual(fakeReactor.runCount, 1)
        self.assertEqual(fakeReactor.spawnCount, 1)


    def test_runUncleanWarnings(self):
        """
        Running with the C{unclean-warnings} option makes L{DistTrialRunner}
        uses the L{UncleanWarningsReporterWrapper}.
        """
        fakeReactor = FakeReactor()
        self.runner._uncleanWarnings = True
        result = self.runner.run(TestCase(), fakeReactor)
        self.assertIsInstance(result, DistReporter)
        self.assertIsInstance(result.original,
                              UncleanWarningsReporterWrapper)


    def test_runWithoutTest(self):
        """
        When the suite contains no test, L{DistTrialRunner} takes a shortcut
        path without launching any process or starting the reactor.
        """
        fakeReactor = object()
        suite = TrialSuite()
        result = self.runner.run(suite, fakeReactor)
        self.assertIsInstance(result, DistReporter)
        output = self.runner._stream.getvalue()
        self.assertIn("Running 0 test", output)
        self.assertIn("PASSED", output)


    def test_runWithoutTestButWithAnError(self):
        """
        Even if there is no test, the suite can contain an error (most likely,
        an import error): this should make the run fail, and the error should
        be printed.
        """
        fakeReactor = object()
        error = ErrorHolder("an error", Failure(RuntimeError("foo bar")))
        result = self.runner.run(error, fakeReactor)
        self.assertIsInstance(result, DistReporter)
        output = self.runner._stream.getvalue()
        self.assertIn("Running 0 test", output)
        self.assertIn("foo bar", output)
        self.assertIn("an error", output)
        self.assertIn("errors=1", output)
        self.assertIn("FAILED", output)


    def test_runUnexpectedError(self):
        """
        If for some reasons we can't connect to the worker process, the test
        suite catches and fails.
        """

        class FakeReactorWithFail(FakeReactor):

            def spawnProcess(self, worker, *args, **kwargs):
                worker.makeConnection(FakeTransport())
                self.spawnCount += 1
                worker._ampProtocol.run = self.failingRun

            def failingRun(self, case, result):
                return fail(RuntimeError("oops"))

        scheduler = FakeScheduler()
        cooperator = Cooperator(scheduler=scheduler)

        fakeReactor = FakeReactorWithFail()
        result = self.runner.run(TestCase(), fakeReactor,
                                 cooperator.cooperate)
        self.assertEqual(fakeReactor.runCount, 1)
        self.assertEqual(fakeReactor.spawnCount, 1)
        scheduler.pump()
        self.assertEqual(1, len(result.original.failures))