diff options
author | Tim Peters <tim@python.org> | 2013-12-04 03:02:05 (GMT) |
---|---|---|
committer | Tim Peters <tim@python.org> | 2013-12-04 03:02:05 (GMT) |
commit | 13e6d23bb13d481caa9e9491b85062b643668d22 (patch) | |
tree | 19dff2bcc78ecb9efa0a0d564977ed9dd90a73bc /Lib/doctest.py | |
parent | 4b7f7acf30991a8e4bcf61eba36cc695036703ca (diff) | |
download | cpython-13e6d23bb13d481caa9e9491b85062b643668d22.zip cpython-13e6d23bb13d481caa9e9491b85062b643668d22.tar.gz cpython-13e6d23bb13d481caa9e9491b85062b643668d22.tar.bz2 |
Issue #19138: doctest's IGNORE_EXCEPTION_DETAIL now allows no detail at all.
(grafted from c80083ad142db2939507800c755082293a87f2de)
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 0b485f1..3f0d9d9 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -314,6 +314,32 @@ def _comment_line(line): else: return '#' +def _strip_exception_details(msg): + # Support for IGNORE_EXCEPTION_DETAIL. + # Get rid of everything except the exception name; in particular, drop + # the possibly dotted module path (if any) and the exception message (if + # any). We assume that a colon is never part of a dotted name, or of an + # exception name. + # E.g., given + # "foo.bar.MyError: la di da" + # return "MyError" + # Or for "abc.def" or "abc.def:\n" return "def". + + start, end = 0, len(msg) + # The exception name must appear on the first line. + i = msg.find("\n") + if i >= 0: + end = i + # retain up to the first colon (if any) + i = msg.find(':', 0, end) + if i >= 0: + end = i + # retain just the exception name + i = msg.rfind('.', 0, end) + if i >= 0: + start = i+1 + return msg[start: end] + class _OutputRedirectingPdb(pdb.Pdb): """ A specialized version of the python debugger that redirects stdout @@ -1320,10 +1346,9 @@ class DocTestRunner: # Another chance if they didn't care about the detail. elif self.optionflags & IGNORE_EXCEPTION_DETAIL: - m1 = re.match(r'(?:[^:]*\.)?([^:]*:)', example.exc_msg) - m2 = re.match(r'(?:[^:]*\.)?([^:]*:)', exc_msg) - if m1 and m2 and check(m1.group(1), m2.group(1), - self.optionflags): + if check(_strip_exception_details(example.exc_msg), + _strip_exception_details(exc_msg), + self.optionflags): outcome = SUCCESS # Report the outcome. |