Package zope :: Package testing :: Module doctest :: Class DocTestParser
[show private | hide private]
[frames | no frames]

Class DocTestParser


A class used to parse strings containing doctest examples.


Method Summary
  get_doctest(self, string, globs, name, filename, lineno)
Extract all doctest examples from the given string, and collect them into a DocTest object.
  get_examples(self, string, name)
Extract all doctest examples from the given string, and return them as a list of Example objects.
  parse(self, string, name)
Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings.
  _check_prefix(self, lines, prefix, name, lineno)
Check that every line in the given list starts with the given prefix; if any line does not, then raise a ValueError.
  _check_prompt_blank(self, lines, indent, name, lineno)
Given the lines of a source string (including prompts and leading indentation), check to make sure that every prompt is followed by a space character.
  _find_options(self, source, name, lineno)
Return a dictionary containing option overrides extracted from option directives in the given source string.
  _min_indent(self, s)
Return the minimum indentation of any non-blank line in s
  _parse_example(self, m, name, lineno)
Given a regular expression match from _EXAMPLE_RE (m), return a pair (source, want), where source is the matched example's source code (with prompts and indentation stripped); and want is the example's expected output (with indentation stripped).
    Inherited from SRE_Pattern
  _IS_BLANK_OR_COMMENT(...)
match(string[, pos[, endpos]]) --> match object or None.

Class Variable Summary
SRE_Pattern _EXAMPLE_RE = ((?:^( *)>>>.*)(?:\n *\.\.\..*)*)\n?((?:(?...
SRE_Pattern _EXCEPTION_RE = ^(Traceback \((?:most recent call last|i...
SRE_Pattern _INDENT_RE = ^( *)(?=\S)
SRE_Pattern _OPTION_DIRECTIVE_RE = #\s*doctest:\s*([^\n'"]*)$

Method Details

get_doctest(self, string, globs, name, filename, lineno)

Extract all doctest examples from the given string, and collect them into a DocTest object.

globs, name, filename, and lineno are attributes for the new DocTest object. See the documentation for DocTest for more information.

get_examples(self, string, name='<string>')

Extract all doctest examples from the given 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.

The optional argument name is a name identifying this string, and is only used for error messages.

parse(self, string, name='<string>')

Divide the given string into examples and intervening text, and return them as a list of alternating Examples and strings. Line numbers for the Examples are 0-based. The optional argument name is a name identifying this string, and is only used for error messages.

_check_prefix(self, lines, prefix, name, lineno)

Check that every line in the given list starts with the given prefix; if any line does not, then raise a ValueError.

_check_prompt_blank(self, lines, indent, name, lineno)

Given the lines of a source string (including prompts and leading indentation), check to make sure that every prompt is followed by a space character. If any line is not followed by a space character, then raise ValueError.

_find_options(self, source, name, lineno)

Return a dictionary containing option overrides extracted from option directives in the given source string.

name is the string's name, and lineno is the line number where the example starts; both are used for error messages.

_min_indent(self, s)

Return the minimum indentation of any non-blank line in s

_parse_example(self, m, name, lineno)

Given a regular expression match from _EXAMPLE_RE (m), return a pair (source, want), where source is the matched example's source code (with prompts and indentation stripped); and want is the example's expected output (with indentation stripped).

name is the string's name, and lineno is the line number where the example starts; both are used for error messages.


Class Variable Details

_EXAMPLE_RE

Type:
SRE_Pattern
Value:
((?:^( *)>>>.*)(?:\n *\.\.\..*)*)\n?((?:(?! *$)(?! *>>>).*$\n?)*)      

_EXCEPTION_RE

Type:
SRE_Pattern
Value:
^(Traceback \((?:most recent call last|innermost last)\):)\s*$(.*?)^(\\
w+.*)                                                                  

_INDENT_RE

Type:
SRE_Pattern
Value:
^( *)(?=\S)                                                            

_OPTION_DIRECTIVE_RE

Type:
SRE_Pattern
Value:
#\s*doctest:\s*([^\n'"]*)$                                             

Generated by Epydoc 2.1 on Fri Jun 24 12:01:21 2005 http://epydoc.sf.net