[Python-checkins] python/dist/src/Lib doctest.py,1.50,1.51
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Mon Aug 9 05:51:49 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12808/Lib
Modified Files:
doctest.py
Log Message:
Drop the excruciating newline requirements on arguments to
Example.__init__. The constructor now adds trailing newlines when
needed, and no longer distinguishes between multi- and single-line
cases for source.
Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** doctest.py 9 Aug 2004 03:31:56 -0000 1.50
--- doctest.py 9 Aug 2004 03:51:46 -0000 1.51
***************
*** 494,515 ****
output. Example defines the following attributes:
! - source: A single python statement, ending in a newline iff the
! statement spans more than one line.
! - want: The expected output from running the source code (either
! from stdout, or a traceback in case of exception). `want`
! should always end with a newline, unless no output is expected,
! - lineno: The line number within the DocTest string containing
this Example where the Example begins. This line number is
zero-based, with respect to the beginning of the DocTest.
"""
def __init__(self, source, want, lineno):
! # Check invariants.
! if (source[-1:] == '\n') != ('\n' in source[:-1]):
! raise AssertionError("source must end with newline iff "
! "source contains more than one line")
! if want and want[-1] != '\n':
! raise AssertionError("non-empty want must end with newline")
# Store properties.
self.source = source
--- 494,515 ----
output. Example defines the following attributes:
! - source: A single Python statement, always ending with a newline.
! The constructor adds a newline if needed.
! - want: The expected output from running the source code (either
! from stdout, or a traceback in case of exception). `want` ends
! with a newline unless it's empty, in which case it's an empty
! string. The constructor adds a newline if needed.
! - lineno: The line number within the DocTest string containing
this Example where the Example begins. This line number is
zero-based, with respect to the beginning of the DocTest.
"""
def __init__(self, source, want, lineno):
! # Normalize inputs.
! if not source.endswith('\n'):
! source += '\n'
! if want and not want.endswith('\n'):
! want += '\n'
# Store properties.
self.source = source
***************
*** 626,632 ****
>>> for x in Parser('<string>', text).get_examples():
... print (x.source, x.want, x.lineno)
! ('x, y = 2, 3 # no output expected', '', 1)
('if 1:\\n print x\\n print y\\n', '2\\n3\\n', 2)
! ('x+y', '5\\n', 9)
"""
examples = []
--- 626,632 ----
>>> for x in Parser('<string>', text).get_examples():
... print (x.source, x.want, x.lineno)
! ('x, y = 2, 3 # no output expected\\n', '', 1)
('if 1:\\n print x\\n print y\\n', '2\\n3\\n', 2)
! ('x+y\\n', '5\\n', 9)
"""
examples = []
***************
*** 1284,1288 ****
# trailing newline. Rather than analyze that, always
# append one (it never hurts).
! exec compile(example.source + '\n', "<string>", "single",
compileflags, 1) in test.globs
exception = None
--- 1284,1288 ----
# trailing newline. Rather than analyze that, always
# append one (it never hurts).
! exec compile(example.source, "<string>", "single",
compileflags, 1) in test.globs
exception = None
More information about the Python-checkins
mailing list