Sybil文档测试工具的扩展。
项目描述
sybil-extras
Sybil的附加组件。
安装
$ pip install sybil-extras
使用
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.rest.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])
pytest_collect_file = sybil.pytest()
ShellCommandEvaluator
"""Use ShellCommandEvaluator to run shell commands against the code block."""
import sys
from sybil import Sybil
from sybil.parsers.rest.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])
pytest_collect_file = sybil.pytest()
CustomDirectiveSkipParser
"""Use CustomDirectiveSkipParser to skip code blocks with a custom marker."""
from sybil import Sybil
from sybil.parsers.rest.codeblock import PythonCodeBlockParser
# Similar parsers are available at
# sybil_extras.parsers.markdown.custom_directive_skip and
# sybil_extras.parsers.myst.custom_directive_skip.
from sybil_extras.parsers.rest.custom_directive_skip import (
CustomDirectiveSkipParser,
)
skip_parser = CustomDirectiveSkipParser(directive="custom-marker-skip")
code_block_parser = PythonCodeBlockParser()
sybil = Sybil(parsers=[skip_parser, code_block_parser])
pytest_collect_file = sybil.pytest()
这允许您以与Sybil文档中描述的跳过示例相同的方式跳过代码块,例如,使用自定义文本替换“跳过”一词,例如 custom-marker-skip。
项目详情
下载文件
下载适用于您平台文件的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
sybil_extras-2024.9.22.1.tar.gz (22.7 kB 查看哈希)
构建分发
关闭
哈希 for sybil_extras-2024.9.22.1-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cd87bc4cb7ec53be08f19fbe2ddd8cf181702cec5ddb608cb0ac0df2bb8d03c2 |
|
MD5 | 89999907548bf40f6b8b27f32ba09abc |
|
BLAKE2b-256 | d837ba049a5fa768e3b1c0bcb2ca88969e81d1215480411068a978b71d8d23fa |