Esempio n. 1
0
 def test_iterateNestedTestSuite(self):
     """
     L{_iterateTests} returns tests that are in nested test suites.
     """
     test = self.TestCase()
     suite = runner.TestSuite([runner.TestSuite([test])])
     self.assertEqual([test], list(unittest._iterateTests(suite)))
Esempio n. 2
0
 def test_iterateIsLeftToRightDepthFirst(self):
     """
     L{_iterateTests} returns tests in left-to-right, depth-first order.
     """
     test = self.TestCase()
     suite = runner.TestSuite([runner.TestSuite([test]), self])
     self.assertEqual([test, self], list(unittest._iterateTests(suite)))
Esempio n. 3
0
 def test_iterateTestCase(self):
     """
     L{_iterateTests} on a single test case returns a list containing that
     test case.
     """
     test = self.TestCase()
     self.assertEqual([test], list(unittest._iterateTests(test)))
Esempio n. 4
0
 def test_iterateIsLeftToRightDepthFirst(self):
     """
     L{_iterateTests} returns tests in left-to-right, depth-first order.
     """
     test = unittest.TestCase()
     suite = runner.TestSuite([runner.TestSuite([test]), self])
     self.assertEqual([test, self], list(unittest._iterateTests(suite)))
Esempio n. 5
0
 def test_iterateTestCase(self):
     """
     L{_iterateTests} on a single test case returns a list containing that
     test case.
     """
     test = unittest.TestCase()
     self.assertEqual([test], list(unittest._iterateTests(test)))
Esempio n. 6
0
 def test_iterateNestedTestSuite(self):
     """
     L{_iterateTests} returns tests that are in nested test suites.
     """
     test = unittest.TestCase()
     suite = runner.TestSuite([runner.TestSuite([test])])
     self.assertEqual([test], list(unittest._iterateTests(suite)))
Esempio n. 7
0
        def runTests():
            testCases = iter(list(_iterateTests(suite)))

            workerDeferreds = []
            for worker in ampWorkers:
                workerDeferreds.append(self._driveWorker(worker, result, testCases, cooperate=cooperate))
            return DeferredList(workerDeferreds, consumeErrors=True, fireOnOneErrback=True)
Esempio n. 8
0
def testNames(tests):
    """
    Return the id of each test within the given test suite or case.
    """
    names = []
    for test in unittest._iterateTests(tests):
        names.append(test.id())
    return names
def testNames(tests):
    """
    Return the id of each test within the given test suite or case.
    """
    names = []
    for test in unittest._iterateTests(tests):
        names.append(test.id())
    return names
Esempio n. 10
0
 def test_iterateSingletonTestSuite(self):
     """
     L{_iterateTests} on a test suite that contains a single test case
     returns a list containing that test case.
     """
     test = self.TestCase()
     suite = runner.TestSuite([test])
     self.assertEqual([test], list(unittest._iterateTests(suite)))
Esempio n. 11
0
 def test_iterateSingletonTestSuite(self):
     """
     L{_iterateTests} on a test suite that contains a single test case
     returns a list containing that test case.
     """
     test = unittest.TestCase()
     suite = runner.TestSuite([test])
     self.assertEqual([test], list(unittest._iterateTests(suite)))
Esempio n. 12
0
        def runTests():
            testCases = iter(list(_iterateTests(suite)))

            workerDeferreds = []
            for worker in ampWorkers:
                workerDeferreds.append(
                    self._driveWorker(worker,
                                      result,
                                      testCases,
                                      cooperate=cooperate))
            return DeferredList(workerDeferreds,
                                consumeErrors=True,
                                fireOnOneErrback=True)
Esempio n. 13
0
    def _runWithoutDecoration(self, test):
        """
        Private helper that runs the given test but doesn't decorate it.
        """
        result = self._makeResult()
        # decorate the suite with reactor cleanup and log starting
        # This should move out of the runner and be presumed to be
        # present
        suite = TrialSuite([test])
        startTime = time.time()
        if self.mode == self.DRY_RUN:
            for single in unittest._iterateTests(suite):
                result.startTest(single)
                result.addSuccess(single)
                result.stopTest(single)
        else:
            if self.mode == self.DEBUG:
                # open question - should this be self.debug() instead.
                debugger = self._getDebugger()
                run = lambda: debugger.runcall(suite.run, result)
            else:
                run = lambda: suite.run(result)

            oldDir = self._setUpTestdir()
            try:
                self._setUpLogFile()
                run()
            finally:
                self._tearDownLogFile()
                self._tearDownTestdir(oldDir)

        endTime = time.time()
        done = getattr(result, 'done', None)
        if done is None:
            warnings.warn(
                "%s should implement done() but doesn't. Falling back to "
                "printErrors() and friends." % reflect.qual(result.__class__),
                category=DeprecationWarning,
                stacklevel=3)
            result.printErrors()
            result.writeln(result.separator)
            result.writeln('Ran %d tests in %.3fs', result.testsRun,
                           endTime - startTime)
            result.write('\n')
            result.printSummary()
        else:
            result.done()
        return result
Esempio n. 14
0
    def _runWithoutDecoration(self, test):
        """
        Private helper that runs the given test but doesn't decorate it.
        """
        result = self._makeResult()
        # decorate the suite with reactor cleanup and log starting
        # This should move out of the runner and be presumed to be
        # present
        suite = TrialSuite([test])
        startTime = time.time()
        if self.mode == self.DRY_RUN:
            for single in unittest._iterateTests(suite):
                result.startTest(single)
                result.addSuccess(single)
                result.stopTest(single)
        else:
            if self.mode == self.DEBUG:
                # open question - should this be self.debug() instead.
                debugger = self._getDebugger()
                run = lambda: debugger.runcall(suite.run, result)
            else:
                run = lambda: suite.run(result)

            oldDir = self._setUpTestdir()
            try:
                self._setUpLogFile()
                run()
            finally:
                self._tearDownLogFile()
                self._tearDownTestdir(oldDir)

        endTime = time.time()
        done = getattr(result, 'done', None)
        if done is None:
            warnings.warn(
                "%s should implement done() but doesn't. Falling back to "
                "printErrors() and friends." % reflect.qual(result.__class__),
                category=DeprecationWarning, stacklevel=3)
            result.printErrors()
            result.writeln(result.separator)
            result.writeln('Ran %d tests in %.3fs', result.testsRun,
                           endTime - startTime)
            result.write('\n')
            result.printSummary()
        else:
            result.done()
        return result
Esempio n. 15
0
 def loadSortedPackages(self, sorter=runner.name):
     """
     Verify that packages are loaded in the correct order.
     """
     import uberpackage
     self.loader.sorter = sorter
     suite = self.loader.loadPackage(uberpackage, recurse=True)
     # XXX: Work around strange, unexplained Zope crap.
     # jml, 2007-11-15.
     suite = unittest.decorate(suite, ITestCase)
     resultingTests = list(unittest._iterateTests(suite))
     manifest = list(self._trialSortAlgorithm(sorter))
     for number, (manifestTest,
                  actualTest) in enumerate(zip(manifest, resultingTests)):
         self.assertEqual(
             manifestTest.name, actualTest.id(),
             "#%d: %s != %s" % (number, manifestTest.name, actualTest.id()))
     self.assertEqual(len(manifest), len(resultingTests))
Esempio n. 16
0
    def loadSortedPackages(self, sorter=runner.name):
        """
        Verify that packages are loaded in the correct order.
        """
        import uberpackage

        self.loader.sorter = sorter
        suite = self.loader.loadPackage(uberpackage, recurse=True)
        # XXX: Work around strange, unexplained Zope crap.
        # jml, 2007-11-15.
        suite = unittest.decorate(suite, ITestCase)
        resultingTests = list(unittest._iterateTests(suite))
        manifest = list(self._trialSortAlgorithm(sorter))
        for number, (manifestTest, actualTest) in enumerate(zip(manifest, resultingTests)):
            self.assertEqual(
                manifestTest.name, actualTest.id(), "#%d: %s != %s" % (number, manifestTest.name, actualTest.id())
            )
        self.assertEqual(len(manifest), len(resultingTests))