[Python-checkins] python/dist/src/Lib doctest.py,1.82,1.83

edloper at users.sourceforge.net edloper at users.sourceforge.net
Thu Aug 26 01:07:05 CEST 2004


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

Modified Files:
	doctest.py 
Log Message:
Only recognize the expected output as an exception if it *starts* with
a traceback message.  I.e., examples that raise exceptions may no
longer generate pre-exception output.  This restores the behavior of
doctest in python 2.3.  The ability to check pre-exception output is
being removed because it makes the documentation simpler; and because
there are very few use cases for it.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- doctest.py	23 Aug 2004 22:42:55 -0000	1.82
+++ doctest.py	25 Aug 2004 23:07:02 -0000	1.83
@@ -1281,15 +1281,14 @@
 
     # 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 traceback stack (`stack`)
     #    - 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\ \(
@@ -1297,9 +1296,9 @@
             |   innermost\ last
             ) \) :
         )
-        \s* $  # toss trailing whitespace on traceback header
-        .*?    # don't blink:  absorb stuff until a line *starts* with \w
-        ^ (?P<msg> \w+ .*)
+        \s* $                # toss trailing whitespace on the header.
+        (?P<stack> .*?)      # don't blink: absorb stuff until...
+        ^ (?P<msg> \w+ .*)   #     a line *starts* with alphanum.
         """, re.VERBOSE | re.MULTILINE | re.DOTALL)
 
     def __run(self, test, compileflags, out):
@@ -1374,13 +1373,10 @@
                                                      exc_info)
                     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,
+                    # The test passes iff the expected exception
+                    # message (`m.group('msg')`) matches the actual
+                    # exception message (`exc_msg`).
+                    if (self._checker.check_output(m.group('msg'), exc_msg,
                                                    self.optionflags)):
                         self.report_success(out, test, example,
                                        got + _exception_traceback(exc_info))



More information about the Python-checkins mailing list