diff options
author | Tim Peters <tim.peters@gmail.com> | 2004-08-22 17:34:58 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2004-08-22 17:34:58 (GMT) |
commit | c50491591dd5987c121d92b1961df69b911b8a5c (patch) | |
tree | 2aa807420486a4a6a7ef390e01b6257111c5eeb6 | |
parent | 2dd2a28802aebce15d945dcc28f4ce62e8b902d9 (diff) | |
download | cpython-c50491591dd5987c121d92b1961df69b911b8a5c.zip cpython-c50491591dd5987c121d92b1961df69b911b8a5c.tar.gz cpython-c50491591dd5987c121d92b1961df69b911b8a5c.tar.bz2 |
_parse_example(): Simplified new code to preserve trailing spaces before
final newline. Anything to get rid of "l" as a variable name <0.5 wink>.
-rw-r--r-- | Lib/doctest.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index ccf976c..fca2f98 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -735,22 +735,18 @@ class DocTestParser: # indented; and then strip their indentation & prompts. source_lines = m.group('source').split('\n') self._check_prompt_blank(source_lines, indent, name, lineno) - self._check_prefix(source_lines[1:], ' '*indent+'.', name, lineno) + self._check_prefix(source_lines[1:], ' '*indent + '.', name, lineno) source = '\n'.join([sl[indent+4:] for sl in source_lines]) - # Divide want into lines; check that it's properly - # indented; and then strip the indentation. + # Divide want into lines; check that it's properly indented; and + # then strip the indentation. Spaces before the last newline should + # be preserved, so plain rstrip() isn't good enough. want = m.group('want') - - # Strip trailing newline and following spaces - l = len(want.rstrip()) - l = want.find('\n', l) - if l >= 0: - want = want[:l] - want_lines = want.split('\n') + if len(want_lines) > 1 and re.match(r' *$', want_lines[-1]): + del want_lines[-1] # forget final newline & spaces after it self._check_prefix(want_lines, ' '*indent, name, - lineno+len(source_lines)) + lineno + len(source_lines)) want = '\n'.join([wl[indent:] for wl in want_lines]) return source, want @@ -1581,7 +1577,7 @@ class OutputChecker: compare `want` and `got`. `indent` is the indentation of the original example. """ - + # If <BLANKLINE>s are being used, then replace blank lines # with <BLANKLINE> in the actual output string. if not (optionflags & DONT_ACCEPT_BLANKLINE): |