[Python-checkins] python/dist/src/Lib doctest.py,1.74,1.75

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Aug 22 19:35:01 CEST 2004


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

Modified Files:
	doctest.py 
Log Message:
_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>.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- doctest.py	22 Aug 2004 14:09:58 -0000	1.74
+++ doctest.py	22 Aug 2004 17:34:58 -0000	1.75
@@ -735,22 +735,18 @@
         # 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 @@
         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):



More information about the Python-checkins mailing list