summaryrefslogtreecommitdiffstats
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-08-13 03:55:05 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-08-13 03:55:05 (GMT)
commit41a65ea7fec64be031b79041ebba875bde1155d6 (patch)
treeb44ebe3063263cf2a32ad121d4e008b6bed64692 /Lib/doctest.py
parentf076953eb13caf629c81c3656cc0f178c7a91b1d (diff)
downloadcpython-41a65ea7fec64be031b79041ebba875bde1155d6.zip
cpython-41a65ea7fec64be031b79041ebba875bde1155d6.tar.gz
cpython-41a65ea7fec64be031b79041ebba875bde1155d6.tar.bz2
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.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py42
1 files changed, 26 insertions, 16 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py
index fe23064..aa523a6 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -1191,16 +1191,27 @@ class DocTestRunner:
#/////////////////////////////////////////////////////////////////
# 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)
+ # 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):
"""
@@ -1274,20 +1285,19 @@ class DocTestRunner:
exc_info)
failures += 1
else:
- exc_hdr = m.group('hdr')+'\n' # Exception header
+ 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(m.group('out'), got,
+ if (self._checker.check_output(e_want, got,
self.optionflags) and
- self._checker.check_output(m.group('exc'), exc_msg,
+ self._checker.check_output(e_msg, exc_msg,
self.optionflags)):
- # Is +exc_msg the right thing here??
self.report_success(out, test, example,
- got+_exception_traceback(exc_info))
+ got + _exception_traceback(exc_info))
else:
self.report_failure(out, test, example,
- got+_exception_traceback(exc_info))
+ got + _exception_traceback(exc_info))
failures += 1
# Restore the option flags (in case they were modified)