[Python-checkins] python/dist/src/Lib doctest.py,1.64,1.65

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Fri Aug 13 05:55:07 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6538/Lib

Modified Files:
	doctest.py 
Log Message:
Doctest has new traceback gimmicks in 2.4.  While trying to document
them (which they are now), I had to rewrite the code to understand
it.  This has got to be the most DWIM part of doctest -- but in context
is really necessary.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.64
retrieving revision 1.65
diff -C2 -d -r1.64 -r1.65
*** doctest.py	13 Aug 2004 01:52:59 -0000	1.64
--- doctest.py	13 Aug 2004 03:55:05 -0000	1.65
***************
*** 1192,1205 ****
  
      # A regular expression for handling `want` strings that contain
!     # expected exceptions.  It divides `want` into two pieces: the
!     # pre-exception output (`out`) and the exception message (`exc`),
!     # as generated by traceback.format_exception_only().  (I assume
!     # that the exception_only message is the first non-indented line
!     # starting with word characters after the "Traceback ...".)
!     _EXCEPTION_RE = re.compile(('^(?P<out>.*)'
!                                 '^(?P<hdr>Traceback \((?:%s|%s)\):)\s*$.*?'
!                                 '^(?P<exc>\w+.*)') %
!                                ('most recent call last', 'innermost last'),
!                                re.MULTILINE | re.DOTALL)
  
      def __run(self, test, compileflags, out):
--- 1192,1216 ----
  
      # A regular expression for handling `want` strings that contain
!     # expected exceptions.  It divides `want` into three pieces:
!     #    - the pre-exception output (`want`)
!     #    - the traceback header line (`hdr`)
!     #    - the exception message (`msg`), as generated by
!     #      traceback.format_exception_only()
!     # `msg` may have multiple lines.  We assume/require that the
!     # exception message is the first non-indented line starting with a word
!     # character following the traceback header line.
!     _EXCEPTION_RE = re.compile(r"""
!         (?P<want> .*?)   # suck up everything until traceback header
!         # Grab the traceback header.  Different versions of Python have
!         # said different things on the first traceback line.
!         ^(?P<hdr> Traceback\ \(
!             (?: most\ recent\ call\ last
!             |   innermost\ last
!             ) \) :
!         )
!         \s* $  # toss trailing whitespace on traceback header
!         .*?    # don't blink:  absorb stuff until a line *starts* with \w
!         ^ (?P<msg> \w+ .*)
!         """, re.VERBOSE | re.MULTILINE | re.DOTALL)
  
      def __run(self, test, compileflags, out):
***************
*** 1275,1292 ****
                      failures += 1
                  else:
!                     exc_hdr = m.group('hdr')+'\n' # Exception header
                      # The test passes iff the pre-exception output and
                      # the exception description match the values given
                      # in `want`.
!                     if (self._checker.check_output(m.group('out'), got,
                                                     self.optionflags) and
!                         self._checker.check_output(m.group('exc'), exc_msg,
                                                     self.optionflags)):
-                         # 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
  
--- 1286,1302 ----
                      failures += 1
                  else:
!                     e_want, e_msg = m.group('want', 'msg')
                      # The test passes iff the pre-exception output and
                      # the exception description match the values given
                      # in `want`.
!                     if (self._checker.check_output(e_want, got,
                                                     self.optionflags) and
!                         self._checker.check_output(e_msg, exc_msg,
                                                     self.optionflags)):
                          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