[Python-checkins] python/dist/src/Lib doctest.py,1.47,1.48

edloper at users.sourceforge.net edloper at users.sourceforge.net
Mon Aug 9 04:56:04 CEST 2004


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

Modified Files:
	doctest.py 
Log Message:
Changed Parser.get_examples() to return a list of Example objects,
rather than a list of triples.


Index: doctest.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/doctest.py,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** doctest.py	9 Aug 2004 02:45:41 -0000	1.47
--- doctest.py	9 Aug 2004 02:56:02 -0000	1.48
***************
*** 494,502 ****
      output.  Example defines the following attributes:
  
!       - source: The source code that should be run.  It ends with a
!         newline iff the source spans more than one line.
  
!       - want: The expected output from running the source code.  If
!         not empty, then this string ends with a newline.
  
        - lineno: The line number within the DocTest string containing
--- 494,503 ----
      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
***************
*** 551,556 ****
          # Parse the docstring.
          self.docstring = docstring
!         examples = Parser(name, docstring).get_examples()
!         self.examples = [Example(*example) for example in examples]
  
      def __repr__(self):
--- 552,556 ----
          # Parse the docstring.
          self.docstring = docstring
!         self.examples = Parser(name, docstring).get_examples()
  
      def __repr__(self):
***************
*** 606,622 ****
      def get_examples(self):
          """
!         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 = '''
--- 606,614 ----
      def get_examples(self):
          """
!         Extract all doctest examples, from the string, and return them
!         as a list of `Example` objects.  Line numbers are 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 = '''
***************
*** 633,637 ****
          ...        '''
          >>> 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)
--- 625,629 ----
          ...        '''
          >>> 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)
***************
*** 649,653 ****
              if self._IS_BLANK_OR_COMMENT.match(source):
                  continue
!             examples.append( (source, want, lineno) )
  
              # Update lineno (lines inside this example)
--- 641,645 ----
              if self._IS_BLANK_OR_COMMENT.match(source):
                  continue
!             examples.append( Example(source, want, lineno) )
  
              # Update lineno (lines inside this example)



More information about the Python-checkins mailing list