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_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 range(10):
            suite.addTest(TestCase())
        self.runner.run(suite, fakeReactor)
Beispiel #3
0
 def run(self, testCase):
     """
     Run a test case by name.
     """
     case = self._loader.loadByName(testCase)
     suite = TrialSuite([case], self._forceGarbageCollection)
     suite.run(self._result)
     return {'success': True}
 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_run(self):
     """
     C{run} starts the reactor exactly once and spawns each of the workers
     exactly once.
     """
     fakeReactor = FakeReactor()
     suite = TrialSuite()
     for i in range(10):
         suite.addTest(TestCase())
     self.runner.run(suite, fakeReactor)
     self.assertEqual(fakeReactor.runCount, 1)
     self.assertEqual(fakeReactor.spawnCount, self.runner._workerNumber)
 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)