Additions to Sybil, the documentation testing tool.
Project description
sybil-extras
Add ons for Sybil.
Installation
$ pip install sybil-extras
Usage
MultiEvaluator
"""Use MultiEvaluator to run multiple evaluators on the same parser."""
from sybil import Example, Sybil
from sybil.evaluators.python import PythonEvaluator
from sybil.parsers.codeblock import CodeBlockParser
from sybil_extras.evaluators.multi import MultiEvaluator
def _evaluator_1(example: Example) -> None:
"""Check that the example is long enough."""
minimum_length = 50
assert len(example.parsed) >= minimum_length
evaluators = [_evaluator_1, PythonEvaluator()]
multi_evaluator = MultiEvaluator(evaluators=evaluators)
parser = CodeBlockParser(language="python", evaluator=multi_evaluator)
sybil = Sybil(parsers=[parser])
ShellCommandEvaluator
"""Use ShellCommandEvaluator to run shell commands against the code block."""
import sys
from sybil import Sybil
from sybil.parsers.codeblock import CodeBlockParser
from sybil_extras.evaluators.shell_evaluator import ShellCommandEvaluator
evaluator = ShellCommandEvaluator(
args=[sys.executable, "-m", "mypy"],
# The code block is written to a temporary file
# with this suffix.
tempfile_suffix=".py",
# Pad the temporary file with newlines so that the
# line numbers in the error messages match the
# line numbers in the source document.
pad_file=True,
# Don't write any changes back to the source document.
# This option is useful when running a linter or formatter
# which modifies the code.
write_to_file=False,
)
parser = CodeBlockParser(language="python", evaluator=evaluator)
sybil = Sybil(parsers=[parser])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sybil_extras-2024.9.10.tar.gz
(15.7 kB
view hashes)
Built Distribution
Close
Hashes for sybil_extras-2024.9.10-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8246c55db620aa938824a4b9babdbde5a3ae7137091250e5c327dc84f0c6a4b |
|
MD5 | 2b22f495f352a1cc286e6c8f0d88ceac |
|
BLAKE2b-256 | 2af42f8d00011eb1f11f329aa273244c1ddf28c83781845ae9cc3feb1b1ffde9 |