[Python-checkins] python/dist/src/Lib doctest.py,1.61,1.62
edloper at users.sourceforge.net
edloper at users.sourceforge.net
Thu Aug 12 04:41:32 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10037/dist/src/Lib
Modified Files:
doctest.py
Log Message:
- Changed output of DocTestParser.get_program() to make it easier to
visually distinguish the expected output from the comments (use
"##" to mark expected outputs, and "#" to mark comments).
- If the string given to DocTestParser.get_program() is indented, then
strip its indentation. (In particular, find the min indentation of
non-blank lines, and strip that indentation from all lines.)
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** doctest.py 12 Aug 2004 02:34:27 -0000 1.61
--- doctest.py 12 Aug 2004 02:41:30 -0000 1.62
***************
*** 596,607 ****
print y
# Expected:
! # 2
! # 3
#
! # Some text.
x+y
# Expected:
! # 5
"""
output = []
charnum, lineno = 0, 0
--- 596,613 ----
print y
# Expected:
! ## 2
! ## 3
#
! # Some text.
x+y
# Expected:
! ## 5
"""
+ string = string.expandtabs()
+ # If all lines begin with the same indentation, then strip it.
+ min_indent = self._min_indent(string)
+ if min_indent > 0:
+ string = '\n'.join([l[min_indent:] for l in string.split('\n')])
+
output = []
charnum, lineno = 0, 0
***************
*** 621,625 ****
if want:
output.append('# Expected:')
! output.extend(['# '+l for l in want.split('\n')])
# Update the line number & char number.
--- 627,631 ----
if want:
output.append('# Expected:')
! output.extend(['## '+l for l in want.split('\n')])
# Update the line number & char number.
***************
*** 703,711 ****
return options
def _comment_line(self, line):
"Return a commented form of the given line"
line = line.rstrip()
if line:
! return '# '+line
else:
return '#'
--- 709,725 ----
return options
+ # This regular expression finds the indentation of every non-blank
+ # line in a string.
+ _INDENT_RE = re.compile('^([ ]+)(?=\S)', re.MULTILINE)
+
+ def _min_indent(self, s):
+ "Return the minimum indentation of any non-blank line in `s`"
+ return min([len(indent) for indent in self._INDENT_RE.findall(s)])
+
def _comment_line(self, line):
"Return a commented form of the given line"
line = line.rstrip()
if line:
! return '# '+line
else:
return '#'
***************
*** 2180,2200 ****
>>> print script_from_examples(text)
! # Here are examples of simple math.
#
! # Python has super accurate integer addition
#
2 + 2
# Expected:
! # 5
#
! # And very friendly error messages:
#
1/0
# Expected:
! # To Infinity
! # And
! # Beyond
#
! # You can use logic if you want:
#
if 0:
--- 2194,2214 ----
>>> print script_from_examples(text)
! # Here are examples of simple math.
#
! # Python has super accurate integer addition
#
2 + 2
# Expected:
! ## 5
#
! # And very friendly error messages:
#
1/0
# Expected:
! ## To Infinity
! ## And
! ## Beyond
#
! # You can use logic if you want:
#
if 0:
***************
*** 2203,2207 ****
<BLANKLINE>
#
! # Ho hum
"""
--- 2217,2221 ----
<BLANKLINE>
#
! # Ho hum
"""
More information about the Python-checkins
mailing list