[Proctor-checkins] CVS: Proctor/proctorlib cui.py,1.18,1.19 runner.py,1.6,1.7
Status: Alpha
Brought to you by:
doughellmann
From: Doug H. <dou...@us...> - 2003-05-04 22:37:25
|
Update of /cvsroot/proctor/Proctor/proctorlib In directory sc8-pr-cvs1:/tmp/cvs-serv1108/proctorlib Modified Files: cui.py runner.py Log Message: Move all of the parsable output handling stuff out of the CLI and into the ProctorParsableTestResult class so it can be shared with the BackgroundTestRunner. Index: cui.py =================================================================== RCS file: /cvsroot/proctor/Proctor/proctorlib/cui.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** cui.py 23 Apr 2003 12:20:43 -0000 1.18 --- cui.py 4 May 2003 22:37:22 -0000 1.19 *************** *** 105,109 **** return ! def optionHandler_norun(self): """Do not run the tests """ --- 105,109 ---- return ! def optionHandler_no_run(self): """Do not run the tests """ *************** *** 156,223 **** return - def showTestBegin(self, test): - trace.into('proctorbatch', 'showTestBegin', test=test) - desc = test.shortDescription() or str(test) - if self.parsable_mode: - print - print '*** begin test' - - self.num_tests_run += 1 - - progress_line = '%3d/%3d %s ...' % (self.num_tests_run, - self.num_tests, - desc, - ) - - print progress_line, - trace.outof() - return - - def showTestEnd(self, test): - trace.into('proctorbatch', 'showTestEnd', test=test) - if self.parsable_mode: - print '*** end test' - trace.outof() - return - - def showTestSuccess(self, test): - trace.into('proctorbatch', 'showTestSuccess', test=test) - print 'ok' - trace.outof() - return - - def showTestFailure(self, test, err): - trace.into('proctorbatch', 'showTestFailure', test=test, err=err) - print 'FAIL' - print self._exc_info_to_string(err) - print - trace.outof() - return - - def showTestError(self, test, err): - trace.into('proctorbatch', 'showTestError', test=test, err=err) - print 'ERROR' - print self._exc_info_to_string(err) - trace.outof() - return - - def _exc_info_to_string(self, err): - """Converts a sys.exc_info()-style tuple of values into a string.""" - return string.join(apply(traceback.format_exception, err), '') - def runTests(self, module_tree): - start_time = time.time() - if self.parsable_mode: - print '*** start run' - elif self.verboseLevel: - print - test_suite = module_tree.getTestSuite(full=1, category=self.category) if self.interleaved: ! test_runner = proctorlib.runner.TestRunner(self) else: - verbosity = self.verboseLevel + 1 test_runner = unittest.TextTestRunner(descriptions=0, verbosity=verbosity) --- 156,176 ---- return def runTests(self, module_tree): test_suite = module_tree.getTestSuite(full=1, category=self.category) + verbosity = self.verboseLevel + 1 + if self.interleaved: ! if self.parsable_mode: ! result_factory = proctorlib.runner.ProctorParsableTestResult ! else: ! result_factory = proctorlib.runner.ProctorTestResult ! ! test_runner = proctorlib.runner.TestRunner( ! verbosity=verbosity, ! resultFactory=result_factory, ! ) else: test_runner = unittest.TextTestRunner(descriptions=0, verbosity=verbosity) *************** *** 226,280 **** # Set up progress management info. # - self.num_tests = test_suite.countTestCases() - self.num_tests_run = 0 - result = test_runner.run(test_suite) - run = result.testsRun - end_time = time.time() - - elapsed_time = float(end_time - start_time) - - if self.parsable_mode: - print - print '*** begin summary' - - if self.interleaved or self.parsable_mode: - # - # If we are running verbosely, the test runner will - # print the summary. Otherwise, we want to do it - # ourselves. - # - - print - print "Ran %d test%s in %.3fs" % (run, run == 1 and "" or "s", elapsed_time) - print - - if not result.wasSuccessful(): - - failed, errored = map(len, (result.failures, result.errors)) - - if failed: - failures = "failures=%d" % failed - else: - failures = '' - - if errored: - if failed: - errors = ", errors=%d" % errored - else: - errors = "errors=%d" % errored - else: - errors = '' - - print "FAILED (%s%s)" % (failures, errors) - - else: - print "OK" - - if self.parsable_mode: - print '*** end summary' - print '*** end run' - return result --- 179,184 ---- *************** *** 287,295 **** #self.statusMessage('data=%s' % data) if self.parsable_mode: ! desc = '<%s)' % (node.shortDescription() or '') else: desc = node.shortDescription() or '' if desc: ! desc = '<%s)' % desc id = node.id() print '%s %s' % (id, desc) --- 191,199 ---- #self.statusMessage('data=%s' % data) if self.parsable_mode: ! desc = '(%s)' % (node.shortDescription() or '') else: desc = node.shortDescription() or '' if desc: ! desc = '(%s)' % desc id = node.id() print '%s %s' % (id, desc) *************** *** 300,304 **** #moduleTree.walk(self._showTestInfo, None) if self.parsable_mode: ! print '*** Start list' suite = moduleTree.getTestSuite(1, category=self.category) for test in suite._tests: --- 204,208 ---- #moduleTree.walk(self._showTestInfo, None) if self.parsable_mode: ! print '__PROCTOR__ Start list' suite = moduleTree.getTestSuite(1, category=self.category) for test in suite._tests: *************** *** 306,310 **** success = 1 if self.parsable_mode: ! print '*** End list' return success --- 210,214 ---- success = 1 if self.parsable_mode: ! print '__PROCTOR__ End list' return success *************** *** 343,355 **** sys.argv = [ sys.argv[0] ] if self.list_mode: - module_tree = self.getModuleTree(args) success = self.listTests(module_tree) ! elif self.list_categories_mode: ! module_tree = self.getModuleTree(args) success = self.listCategories(module_tree) ! elif self.run_mode: # --- 247,271 ---- sys.argv = [ sys.argv[0] ] + module_tree = self.getModuleTree(args) + + # + # If they asked for a list of the tests, print that + # first. + # if self.list_mode: success = self.listTests(module_tree) ! # ! # If they asked for a list of test categories, ! # print that here. ! # ! if self.list_categories_mode: success = self.listCategories(module_tree) ! # ! # If they asked to have tests run, do that ! # last. ! # ! if self.run_mode: # Index: runner.py =================================================================== RCS file: /cvsroot/proctor/Proctor/proctorlib/runner.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** runner.py 21 Jul 2002 20:42:43 -0000 1.6 --- runner.py 4 May 2003 22:37:22 -0000 1.7 *************** *** 61,64 **** --- 61,65 ---- from StringIO import StringIO import sys + import time import traceback import unittest *************** *** 75,100 **** class ProctorTestResult(unittest.TestResult): ! def __init__(self, app): trace.into('ProctorTestResult', '__init__') ! self.app = app ! self.outputs = {} ! self.output_trap = None ! # ! # Save stdout and stderr handles, since we'll be ! # replacing them later. ! # ! self.stdout = sys.stdout ! self.stderr = sys.stderr unittest.TestResult.__init__(self) trace.outof() return def startTest(self, test): trace.into('ProctorTestResult', 'startTest', test=test) ! self.output_trap = StringIO() ! #sys.stdout = self.output_trap ! #sys.stderr = self.output_trap unittest.TestResult.startTest(self, test) ! self.app.showTestBegin(test) trace.outof() return --- 76,148 ---- class ProctorTestResult(unittest.TestResult): ! def __init__(self, testSuite, verbosity): trace.into('ProctorTestResult', '__init__') ! ! self.num_tests = testSuite.countTestCases() ! self.num_tests_run = 0 ! self.verbosity = verbosity ! unittest.TestResult.__init__(self) + trace.outof() return + + def startRun(self): + self.start_time = time.time() + return + + def endRun(self): + self.end_time = time.time() + return + + def showSummary(self): + run = self.num_tests_run + + elapsed_time = float(self.end_time - self.start_time) + + print + print "Ran %d test%s in %.3fs" % (run, + run == 1 and "" or "s", + elapsed_time) + print + + if not self.wasSuccessful(): + + failed, errored = map(len, (self.failures, self.errors)) + + if failed: + failures = "failures=%d" % failed + else: + failures = '' + + if errored: + if failed: + errors = ", errors=%d" % errored + else: + errors = "errors=%d" % errored + else: + errors = '' + + print "FAILED (%s%s)" % (failures, errors) + + else: + print "OK" + return + def startTest(self, test): trace.into('ProctorTestResult', 'startTest', test=test) ! unittest.TestResult.startTest(self, test) ! ! desc = test.shortDescription() or str(test) ! progress_line = '%3d/%3d %s ...' % (self.num_tests_run, ! self.num_tests, ! desc, ! ) ! print progress_line, ! ! self.num_tests_run += 1 ! trace.outof() return *************** *** 102,120 **** def stopTest(self, test): trace.into('ProctorTestResult', 'stopTest', test=test) ! # ! # Save the test output ! # ! existing_output = self.outputs.get(test.id(), '') ! self.outputs[test.id()] = (existing_output, self.output_trap.getvalue()) ! # ! # Replace stderr and stdout ! # ! #sys.stderr = self.stderr ! #sys.stdout = self.stdout ! # ! # Close up the unit test ! # ! #unittest.TestResult.stopTest(self, test) ! self.app.showTestEnd(test) trace.outof() return --- 150,156 ---- def stopTest(self, test): trace.into('ProctorTestResult', 'stopTest', test=test) ! ! unittest.TestResult.stopTest(self, test) ! trace.outof() return *************** *** 127,132 **** trace.into('TestResult', 'addError', test=test, err=err) unittest.TestResult.addError(self, test, err) ! self.app.showTestError(test, err) ! self.outputs[test.id()] = self._exc_info_to_string(err) trace.outof() return --- 163,168 ---- trace.into('TestResult', 'addError', test=test, err=err) unittest.TestResult.addError(self, test, err) ! print 'ERROR' ! print self._exc_info_to_string(err) trace.outof() return *************** *** 135,140 **** trace.into('TestResult', 'addFailure', test=test, err=err) unittest.TestResult.addFailure(self, test, err) ! self.app.showTestFailure(test, err) ! self.outputs[test.id()] = self._exc_info_to_string(err) trace.outof() return --- 171,177 ---- trace.into('TestResult', 'addFailure', test=test, err=err) unittest.TestResult.addFailure(self, test, err) ! print 'FAIL' ! print self._exc_info_to_string(err) ! print trace.outof() return *************** *** 142,169 **** def addSuccess(self, test): trace.into('TestResult', 'addSuccess', test=test) unittest.TestResult.addSuccess(self, test) ! self.app.showTestSuccess(test) trace.outof() return ! def getOutput(self, testId): ! try: ! return self.outputs[testId] ! except KeyError: ! return ('', '') class TestRunner: ! def __init__(self, app): ! self.app = app return ! def _makeResult(self): ! return ProctorTestResult(app=self.app) def run(self, test): ! result = self._makeResult() test(result) return result --- 179,317 ---- def addSuccess(self, test): trace.into('TestResult', 'addSuccess', test=test) + unittest.TestResult.addSuccess(self, test) ! print 'ok' ! trace.outof() return ! ! class ProctorParsableTestResult(ProctorTestResult): ! "Test results displayed in parsable fashion." ! ! PREFIX = '__PROCTOR__' ! ! def __init__(self, testSuite, verbosity): ! ProctorTestResult.__init__(self, testSuite, verbosity) ! return ! ! def startRun(self): ! self._outputSeparator('Start run') ! ProctorTestResult.startRun(self) ! return ! ! def endRun(self): ! self._outputSeparator('End run') ! ProctorTestResult.endRun(self) ! return ! ! def _outputSeparator(self, message): ! print '%s %s' % (self.PREFIX, message) ! print ! return ! ! def startTest(self, test): ! self._outputSeparator('Start test') ! ! unittest.TestResult.startTest(self, test) ! ! print test.id() ! ! self.num_tests_run += 1 ! ! trace.outof() ! return ! ! def stopTest(self, test): ! ProctorTestResult.stopTest(self, test) ! self._outputSeparator('End test') ! # ! # Show progress ! # ! self._outputSeparator('Start progress') ! progress_line = '%3d/%3d' % (self.num_tests_run, ! self.num_tests, ! ) ! print progress_line ! self._outputSeparator('End progress') ! ! return ! ! def addSuccess(self, test): ! unittest.TestResult.addSuccess(self, test) ! ! self._outputSeparator('Start results') ! print 'ok' ! self._outputSeparator('End results') ! return ! ! def addError(self, test, err): ! unittest.TestResult.addError(self, test, err) ! print self._exc_info_to_string(err) ! ! self._outputSeparator('Start results') ! print 'ERROR' ! self._outputSeparator('End results') ! return ! ! def addFailure(self, test, err): ! unittest.TestResult.addFailure(self, test, err) ! ! print self._exc_info_to_string(err) ! ! self._outputSeparator('Start results') ! print 'FAIL' ! self._outputSeparator('End results') ! return ! ! def showSummary(self): ! self._outputSeparator('Start summary') ! elapsed_time = float(self.end_time - self.start_time) ! ! num_failures = len(self.failures) ! num_errors = len(self.errors) ! ! print 'Failures: %d' % num_failures ! print 'Errors: %d' % num_errors ! successes = (self.num_tests - (num_failures + num_errors)) ! print 'Successes: %d' % successes ! print 'Tests: %d' % self.num_tests_run ! print 'Elapsed time (sec): %.3f' % elapsed_time ! ! if num_failures or num_errors: ! status = 'FAILED' ! else: ! status = 'OK' ! ! print 'Status: %s' % status ! ! self._outputSeparator('End summary') ! return ! + class TestRunner: ! def __init__(self, ! verbosity=1, ! resultFactory=ProctorTestResult, ! ): ! self.verbosity = verbosity ! self.result_factory = resultFactory return ! def _makeResult(self, test): ! return self.result_factory(test, self.verbosity) def run(self, test): ! result = self._makeResult(test) ! ! result.startRun() ! test(result) + + result.endRun() + result.showSummary() return result |