[Python-checkins] python/dist/src/Lib doctest.py,1.60,1.61
edloper at users.sourceforge.net
edloper at users.sourceforge.net
Thu Aug 12 04:34:32 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9201/dist/src/Lib
Modified Files:
doctest.py
Log Message:
- Added __docformat__
- Added comments for some regexps
- If the traceback type/message don't match, then still print full
traceback in report_failure (not just the first & last lines)
- Renamed DocTestRunner.__failure_header -> _failure_header
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -C2 -d -r1.60 -r1.61
*** doctest.py 12 Aug 2004 02:27:44 -0000 1.60
--- doctest.py 12 Aug 2004 02:34:27 -0000 1.61
***************
*** 168,171 ****
--- 168,172 ----
executed.
"""
+ __docformat__ = 'reStructuredText en'
__all__ = [
***************
*** 331,334 ****
--- 332,346 ----
return '%s:\n%s\n' % (tag, msg)
+ def _exception_traceback(exc_info):
+ """
+ Return a string containing a traceback message for the given
+ exc_info tuple (as returned by sys.exc_info()).
+ """
+ # Get a traceback message.
+ excout = StringIO()
+ exc_type, exc_val, exc_tb = exc_info
+ traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
+ return excout.getvalue()
+
# Override some StringIO methods.
class _SpoofOut(StringIO):
***************
*** 468,471 ****
--- 480,488 ----
A class used to parse strings containing doctest examples.
"""
+ # This regular expression is used to find doctest examples in a
+ # string. It defines three groups: `source` is the source code
+ # (including leading indentation and prompts); `indent` is the
+ # indentation of the first (PS1) line of the source code; and
+ # `want` is the expected output (including leading indentation).
_EXAMPLE_RE = re.compile(r'''
# Source consists of a PS1 line followed by zero or more PS2 lines.
***************
*** 480,484 ****
)*)
''', re.MULTILINE | re.VERBOSE)
! _IS_BLANK_OR_COMMENT = re.compile('^[ ]*(#.*)?$').match
def get_doctest(self, string, globs, name, filename, lineno):
--- 497,504 ----
)*)
''', re.MULTILINE | re.VERBOSE)
!
! # This regular expression matcher checks if a given string is a
! # blank line or contains a single comment.
! _IS_BLANK_OR_COMMENT = re.compile(r'^[ ]*(#.*)?$').match
def get_doctest(self, string, globs, name, filename, lineno):
***************
*** 1126,1130 ****
"""
# Print an error message.
! out(self.__failure_header(test, example) +
self._checker.output_difference(example.want, got,
self.optionflags))
--- 1146,1150 ----
"""
# Print an error message.
! out(self._failure_header(test, example) +
self._checker.output_difference(example.want, got,
self.optionflags))
***************
*** 1134,1147 ****
Report that the given example raised an unexpected exception.
"""
! # Get a traceback message.
! excout = StringIO()
! exc_type, exc_val, exc_tb = exc_info
! traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
! exception_tb = excout.getvalue()
! # Print an error message.
! out(self.__failure_header(test, example) +
! _tag_msg("Exception raised", exception_tb))
! def __failure_header(self, test, example):
s = (self.DIVIDER + "\n" +
_tag_msg("Failure in example", example.source))
--- 1154,1161 ----
Report that the given example raised an unexpected exception.
"""
! out(self._failure_header(test, example) +
! _tag_msg("Exception raised", _exception_traceback(exc_info)))
! def _failure_header(self, test, example):
s = (self.DIVIDER + "\n" +
_tag_msg("Failure in example", example.source))
***************
*** 1257,1264 ****
# Is +exc_msg the right thing here??
self.report_success(out, test, example,
! got+exc_hdr+exc_msg)
else:
self.report_failure(out, test, example,
! got+exc_hdr+exc_msg)
failures += 1
--- 1271,1278 ----
# Is +exc_msg the right thing here??
self.report_success(out, test, example,
! got+_exception_traceback(exc_info))
else:
self.report_failure(out, test, example,
! got+_exception_traceback(exc_info))
failures += 1
More information about the Python-checkins
mailing list