diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-08-19 06:49:33 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-08-19 06:49:33 (GMT) |
commit | 1cf3aa6e6615dcddc58e42d4fb214f9e0d90d22c (patch) | |
tree | 6b9f482fa3db48cdc47ca711991120186ac09a9a /Lib/doctest.py | |
parent | caa9798410887317226c4bf89f38d318b8436612 (diff) | |
download | cpython-1cf3aa6e6615dcddc58e42d4fb214f9e0d90d22c.zip cpython-1cf3aa6e6615dcddc58e42d4fb214f9e0d90d22c.tar.gz cpython-1cf3aa6e6615dcddc58e42d4fb214f9e0d90d22c.tar.bz2 |
ELLIPSIS implementation: an ellipsis couldn't match nothing if it
appeared at the end of a line. Repaired that. Also noted that it's
too easy to provoke this implementation into requiring exponential
time, and especially when a test fails. I'll replace the implementation
with an always-efficient one later.
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index c033b0d..f7b29d3 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1468,7 +1468,7 @@ class OutputChecker: # This flag causes doctest to ignore any differences in the # contents of whitespace strings. Note that this can be used # in conjunction with the ELLISPIS flag. - if (optionflags & NORMALIZE_WHITESPACE): + if optionflags & NORMALIZE_WHITESPACE: got = ' '.join(got.split()) want = ' '.join(want.split()) if got == want: @@ -1477,10 +1477,14 @@ class OutputChecker: # The ELLIPSIS flag says to let the sequence "..." in `want` # match any substring in `got`. We implement this by # transforming `want` into a regular expression. - if (optionflags & ELLIPSIS): + if optionflags & ELLIPSIS: + # Remove \n from ...\n, else the newline will be required, + # and (for example) ... on a line by itself can't match + # nothing gracefully. + want_re = want.replace(ELLIPSIS_MARKER + '\n', ELLIPSIS_MARKER) # Escape any special regexp characters - want_re = re.escape(want) - # Replace ellipsis markers ('...') with .* + want_re = re.escape(want_re) + # Replace escaped ellipsis markers ('\.\.\.') with .* want_re = want_re.replace(re.escape(ELLIPSIS_MARKER), '.*') # Require that it matches the entire string; and set the # re.DOTALL flag (with '(?s)'). |