Table of Contents

Class: DocTestParser ./src/peak/util/_doctest.py

A class used to parse strings containing doctest examples.

Methods   
_check_prefix
_check_prompt_blank
_find_options
_min_indent
_parse_example
get_doctest
get_examples
parse
  _check_prefix 
_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.

Exceptions   
ValueError('line %r of the docstring for %s has ' 'inconsistent leading whitespace: %r' %( lineno + i + 1, name, line ) )
  _check_prompt_blank 
_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.

Exceptions   
ValueError('line %r of the docstring for %s ' 'lacks blank after %s: %r' %( lineno + i + 1, name, line [ indent : indent + 3 ], line ) )
  _find_options 
_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.

Exceptions   
ValueError('line %r of the doctest for %s ' 'has an invalid option: %r' %( lineno + 1, name, option ) )
ValueError('line %r of the doctest for %s has an option ' 'directive on a line with no example: %r' %( lineno, name, source ) )
  _min_indent 
_min_indent ( self,  s )

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

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

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


Table of Contents

This document was automatically generated on Mon Nov 11 01:11:04 2024 by HappyDoc version 2.1