[Proctor-checkins] CVS: Proctor/proctorlib runner.py,1.8,1.9
Status: Alpha
Brought to you by:
doughellmann
From: Doug H. <dou...@us...> - 2004-09-08 14:55:24
|
Update of /cvsroot/proctor/Proctor/proctorlib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11093/proctorlib Modified Files: runner.py Log Message: Convert progress lines to show the id of the test instead of the description. Update exception formatting. Index: runner.py =================================================================== RCS file: /cvsroot/proctor/Proctor/proctorlib/runner.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** runner.py 18 Dec 2003 22:20:43 -0000 1.8 --- runner.py 8 Sep 2004 14:55:15 -0000 1.9 *************** *** 55,59 **** # Import system modules # - import string try: from cStringIO import StringIO --- 55,58 ---- *************** *** 63,66 **** --- 62,66 ---- import time import traceback + import types import unittest *************** *** 73,76 **** --- 73,81 ---- # Module # + def _some_str(value): + try: + return str(value) + except: + return '<unprintable %s object>' % type(value).__name__ class ProctorTestResult(unittest.TestResult): *************** *** 138,142 **** unittest.TestResult.startTest(self, test) ! desc = test.shortDescription() or str(test) progress_line = '%3d/%3d %s ...' % (self.num_tests_run, self.num_tests, --- 143,147 ---- unittest.TestResult.startTest(self, test) ! desc = test.id() progress_line = '%3d/%3d %s ...' % (self.num_tests_run, self.num_tests, *************** *** 158,164 **** 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 addError(self, test, err): --- 163,237 ---- return + def _format_exception_only(self, etype, value, *args): + """Format the exception part of a traceback as the output of grep. + + The arguments are the exception type and value such as given by + sys.last_type and sys.last_value. The return value is a list of + strings, each ending in a newline. Normally, the list contains a + single string; however, for SyntaxError exceptions, it contains + several lines that (when printed) display detailed information + about where the syntax error occurred. The message indicating + which exception occurred is the always last string in the list. + """ + list = [] + if type(etype) == types.ClassType: + stype = etype.__name__ + else: + stype = etype + + if value is None: + list.append('%s\n' % str(stype)) + else: + if etype is SyntaxError: + try: + msg, (filename, lineno, offset, line) = value + except: + pass + else: + if not filename: filename = "<string>" + if line is not None: + i = 0 + while i < len(line) and line[i].isspace(): + i = i+1 + list.append('%s:%d:%s\n' % (filename, lineno, line.strip())) + if offset is not None: + s = ' ' + for c in line[i:offset-1]: + if c.isspace(): + s = s + c + else: + s = s + ' ' + list.append('%s^\n' % s) + value = msg + s = _some_str(value) + if s: + list.append('%s: %s\n' % (str(stype), s)) + else: + list.append('%s\n' % str(stype)) + + return list + + def _format_list(self, extracted_list): + """Format a list of traceback entry tuples for printing. + + Given a list of tuples as returned by extract_tb() or + extract_stack(), return a list of strings ready for printing. + Each string in the resulting list corresponds to the item with the + same index in the argument list. Each string ends in a newline; + the strings may contain internal newlines as well, for those items + whose source text line is not None. + """ + list = [] + for filename, lineno, name, line in extracted_list: + item = '%s:%d:%s:%s\n' % (filename,lineno,line.strip(),name) + list.append(item) + return list + def _exc_info_to_string(self, err): """Converts a sys.exc_info()-style tuple of values into a string.""" ! #err_class, err_inst, tb = err ! #formated_exception = self._format_list(traceback.extract_tb(tb, None)) ! formated_exception = traceback.format_exception(*err) ! return ''.join(formated_exception) def addError(self, test, err): |