[Python-checkins] python/dist/src/Lib doctest.py, 1.36.2.18, 1.36.2.19

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Fri Aug 6 04:11:55 CEST 2004


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

Modified Files:
      Tag: tim-doctest-branch
	doctest.py 
Log Message:
Changed Parser to work purely with strings, and Doctest.__init__ to
change them into Examples.  Cleaner separation of concerns.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.36.2.18
retrieving revision 1.36.2.19
diff -C2 -d -r1.36.2.18 -r1.36.2.19
*** doctest.py	6 Aug 2004 01:28:54 -0000	1.36.2.18
--- doctest.py	6 Aug 2004 02:11:52 -0000	1.36.2.19
***************
*** 496,501 ****
          Return the doctest examples from the string.
  
!         This is a list of doctest.Example instances, one Example
!         per doctest test in the string.
  
          >>> text = '''
--- 496,510 ----
          Return the doctest examples from the string.
  
!         This is a list of (source, want, lineno) triples, one per example
!         in the string.  "source" is a single Python statement; it ends
!         with a newline iff the statement contains more than one
!         physical line.  "want" is the expected output from running the
!         example (either from stdout, or a traceback in case of exception).
!         "want" always ends with a newline, unless no output is expected,
!         in which case "want" is an empty string.  "lineno" is the 0-based
!         line number of the first line of "source" within the string.  It's
!         0-based because it's most common in doctests that nothing
!         interesting appears on the same line as opening triple-quote,
!         and so the first interesting line is called "line 1" then.
  
          >>> text = '''
***************
*** 512,527 ****
          ...        '''
          >>> for x in Parser('<string>', text).get_examples():
!         ...     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
          """
          return self._parse(kind='examples')
--- 521,528 ----
          ...        '''
          >>> for x in Parser('<string>', text).get_examples():
!         ...     print x
!         ('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)
          """
          return self._parse(kind='examples')
***************
*** 638,642 ****
              if isPS1(line) or isEmpty(line):
                  if not do_program:
!                     push(Example(source, "", lineno))
                  continue
  
--- 639,643 ----
              if isPS1(line) or isEmpty(line):
                  if not do_program:
!                     push((source, "", lineno))
                  continue
  
***************
*** 660,664 ****
              else:
                  want = "\n".join(want) + "\n"
!                 push(Example(source, want, lineno))
  
          if do_program:
--- 661,665 ----
              else:
                  want = "\n".join(want) + "\n"
!                 push((source, want, lineno))
  
          if do_program:
***************
*** 743,747 ****
          # Parse the docstring.
          self.docstring = docstring
!         self.examples = Parser(name, docstring).get_examples()
  
      def __repr__(self):
--- 744,749 ----
          # Parse the docstring.
          self.docstring = docstring
!         examples = Parser(name, docstring).get_examples()
!         self.examples = [Example(*example) for example in examples]
  
      def __repr__(self):



More information about the Python-checkins mailing list