Module doctest :: Class DocTestParser
[hide private]
[frames] | no frames]

_ClassType DocTestParser

A class used to parse strings containing doctest examples.
Instance Methods [hide private]
 
_IS_BLANK_OR_COMMENT(...)
match(string[, pos[, endpos]]) --> match object or None.
 
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.
 
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='<string>')
Extract all doctest examples from the given string, and return them as a list of Example objects.
 
_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).
 
_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
 
_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.
 
_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.
Class Variables [hide private]
  _EXAMPLE_RE = re.compile(r'(?mx)(?P<source>(?:^(?P<indent> *)>...
  _EXCEPTION_RE = re.compile(r'(?msx)^(?P<hdr>Traceback \((?:mos...
  _OPTION_DIRECTIVE_RE = re.compile(r'(?m)#\s*doctest:\s*([^\n\'...
  _INDENT_RE = re.compile(r'(?m)^( *)(?=\S)')
Method Details [hide private]

_IS_BLANK_OR_COMMENT(...)

 
match(string[, pos[, endpos]]) --> match object or None. Matches zero or more characters at the beginning of the string

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.

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_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.

_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.

_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.

Class Variable Details [hide private]

_EXAMPLE_RE

Value:
re.compile(r'(?mx)(?P<source>(?:^(?P<indent> *)>>>.*)(?:\n *\.\.\..*)*\
)\n?(?P<want>(?:(?! *$)(?! *>>>).*$\n?)*)')

_EXCEPTION_RE

Value:
re.compile(r'(?msx)^(?P<hdr>Traceback \((?:most recent call last|inner\
most last)\):)\s*$(?P<stack>.*?)^(?P<msg>\w+.*)')

_OPTION_DIRECTIVE_RE

Value:
re.compile(r'(?m)#\s*doctest:\s*([^\n\'"]*)$')