API Reference¶
-
class
sybil.
Sybil
(parsers, pattern, path='.', setup=None, teardown=None, fixtures=())¶ An object to provide test runner integration for discovering examples in documentation and ensuring they are correct.
Parameters: - parsers – A sequence of callables. See Parsers.
- path – The path in which documentation source files are found, relative to the path of the Python source file in which this class is instantiated.
- pattern – A
glob
used to match files found in thepath
. Matching files will be parsed for examples. - setup – An optional callable that will be called once before any examples from
a
Document
are evaluated. If provided, it is called with the document’snamespace
. - teardown – An optional callable that will be called after all the examples from
a
Document
have been evaluated. If provided, it is called with the document’snamespace
. - fixtures – An optional sequence of strings specifying the names of fixtures to
be requested when using the
pytest integration. The fixtures will be
inserted into the document’s
namespace
. All scopes of fixture are supported.
-
class
sybil.
Region
(start, end, parsed, evaluator)¶ Parsers should yield instances of this class for each example they discover in a documentation source file.
Parameters:
-
class
sybil.document.
Document
(text, path)¶ This is Sybil’s representation of a documentation source file. It will be instantiated by Sybil and provided to each parser in turn.
-
text
= None¶ This is the text of the documentation source file.
-
path
= None¶ This is the absolute path of the documentation source file.
-
namespace
= None¶ This dictionary is the namespace in which all example parsed from this document will be evaluated.
-
classmethod
parse
(path, *parsers)¶ Read the text from the supplied path and parse it into a document using the supplied parsers.
-
line_column
(position)¶ Return a line and column location in this document based on a byte position.
-
find_region_sources
(start_pattern, end_pattern)¶ This helper method can be called used to extract source text for regions based on the two regular expressions provided.
It will yield a tuple of
(start_match, end_match, source)
for each occurrence ofstart_pattern
in the document’stext
that is followed by an occurrence ofend_pattern
. The matches will be provided as match objects, while the source is provided as a string.
-
-
class
sybil.example.
Example
(document, line, column, region, namespace)¶ This represents a particular example from a documentation source file. It is assembled from the
Document
andRegion
the example comes from and is passed to the region’s evaluator.
-
sybil.parsers.doctest.
FIX_BYTE_UNICODE_REPR
= 1024¶ A doctest option flag that causes byte and unicode literals in doctest expected output to be rewritten such that they are compatible with the version of Python with which the tests are executed.
-
class
sybil.parsers.doctest.
DocTestParser
(optionflags=0)¶ A class to instantiate and include when your documentation makes use of doctest examples.
Parameters: optionflags – doctest option flags to use when evaluating the examples found by this parser.
-
class
sybil.parsers.codeblock.
CodeBlockParser
(future_imports=())¶ A class to instantiate and include when your documentation makes use of codeblock examples.
Parameters: future_imports – An optional list of strings that will be turned into from __future__ import ...
statements and prepended to the code in each of the examples found by this parser.