Skip to main content

Additions to Sybil, the documentation testing tool.

Project description

Build Status codecov PyPI

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.typing import Evaluator

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: list[Evaluator] = [_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 these suffixes.
    tempfile_suffixes=[".example", ".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


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.15.1.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

sybil_extras-2024.9.15.1-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sybil_extras-2024.9.15.1.tar.gz.

File metadata

  • Download URL: sybil_extras-2024.9.15.1.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for sybil_extras-2024.9.15.1.tar.gz
Algorithm Hash digest
SHA256 a3abb83ae8c99c5bd427b3f0b184a43f717e0a7f1b8b4e7fd09ad3a7a695d54b
MD5 9ed7dbc2da26e4f23f0c42fe46f80cc7
BLAKE2b-256 371fbd6493bacddd893d4f3e8574501a570d07ab1f40c51ef58e54555815b237

See more details on using hashes here.

File details

Details for the file sybil_extras-2024.9.15.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sybil_extras-2024.9.15.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f7383d3e2911d50e2883a60c411b3b9cc529e54570d65e3dd91033abd0ea3818
MD5 c95c238bd9b0bd8f1e748cba7ca82ae8
BLAKE2b-256 d5f668e712ccf4ca7e77ddc7859c48b42b357230651a0c38c72b6a420d09cbef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page