[Python-checkins] python/dist/src/Lib unittest.py,1.32,1.33

purcell at users.sourceforge.net purcell at users.sourceforge.net
Sat Dec 6 08:03:15 EST 2003


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv32033/Lib
Modified Files:
	unittest.py 
Log Message:
Variation of Thomas Heller's patch (722638) for improving readability
of test failure output.
Irrelevant traceback levels are pruned from formatted traceback strings.
Index: unittest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/unittest.py,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** unittest.py	26 Oct 2003 16:38:16 -0000	1.32
--- unittest.py	6 Dec 2003 13:03:13 -0000	1.33
***************
*** 47,51 ****
 __author__ = "Steve Purcell"
 __email__ = "stephen_purcell at yahoo dot com"
! __version__ = "#Revision: 1.62 $"[11:-2]
 
 import time
--- 47,51 ----
 __author__ = "Steve Purcell"
 __email__ = "stephen_purcell at yahoo dot com"
! __version__ = "#Revision: 1.63 $"[11:-2]
 
 import time
***************
*** 91,94 ****
--- 91,96 ----
 return "%s.%s" % (cls.__module__, cls.__name__)
 
+ __unittest = 1
+ 
 class TestResult:
 """Holder for test result information.
***************
*** 120,129 ****
 returned by sys.exc_info().
 """
! self.errors.append((test, self._exc_info_to_string(err)))
 
 def addFailure(self, test, err):
 """Called when an error has occurred. 'err' is a tuple of values as
 returned by sys.exc_info()."""
! self.failures.append((test, self._exc_info_to_string(err)))
 
 def addSuccess(self, test):
--- 122,131 ----
 returned by sys.exc_info().
 """
! self.errors.append((test, self._exc_info_to_string(err, test)))
 
 def addFailure(self, test, err):
 """Called when an error has occurred. 'err' is a tuple of values as
 returned by sys.exc_info()."""
! self.failures.append((test, self._exc_info_to_string(err, test)))
 
 def addSuccess(self, test):
***************
*** 139,145 ****
 self.shouldStop = True
 
! def _exc_info_to_string(self, err):
 """Converts a sys.exc_info()-style tuple of values into a string."""
! return ''.join(traceback.format_exception(*err))
 
 def __repr__(self):
--- 141,165 ----
 self.shouldStop = True
 
! def _exc_info_to_string(self, err, test):
 """Converts a sys.exc_info()-style tuple of values into a string."""
! exctype, value, tb = err
! # Skip test runner traceback levels
! while tb and self._is_relevant_tb_level(tb):
! tb = tb.tb_next
! if exctype is test.failureException:
! # Skip assert*() traceback levels
! length = self._count_relevant_tb_levels(tb)
! return ''.join(traceback.format_exception(exctype, value, tb, length))
! return ''.join(traceback.format_exception(exctype, value, tb))
! 
! def _is_relevant_tb_level(self, tb):
! return tb.tb_frame.f_globals.has_key('__unittest')
! 
! def _count_relevant_tb_levels(self, tb):
! length = 0
! while tb and not self._is_relevant_tb_level(tb):
! length += 1
! tb = tb.tb_next
! return length
 
 def __repr__(self):
***************
*** 148,152 ****
 len(self.failures))
 
- 
 class TestCase:
 """A class whose instances are single test cases.
--- 168,171 ----
***************
*** 275,282 ****
 if sys.platform[:4] == 'java': ## tracebacks look different in Jython
 return (exctype, excvalue, tb)
! newtb = tb.tb_next
! if newtb is None:
! return (exctype, excvalue, tb)
! return (exctype, excvalue, newtb)
 
 def fail(self, msg=None):
--- 294,298 ----
 if sys.platform[:4] == 'java': ## tracebacks look different in Jython
 return (exctype, excvalue, tb)
! return (exctype, excvalue, tb)
 
 def fail(self, msg=None):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /