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)))
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)))
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)))
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)))
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)))
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)))
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)
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 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)))
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)))
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)
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
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))
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))