Skip to content
lsdocs plugin SDK API

lsdocs_plugin.testing #

Run a plugin's handlers in-process, as the host would, for tests.

Each function returns (result, events): the handler's result normalized to the full protocol shape, and the events it sent (log lines, progress, diagnostics) as dicts with a kind key:

from lsdocs_plugin import testing

result, events = testing.parse(plugin, "a.txt", "hello")
assert result["document"]["children"][0]["value"] == "hello"

variable Result #

Result = tuple[dict[str, Any], list[dict[str, Any]]]

function call #

call(plugin: Plugin, method: str, params: dict[str, Any] | None = None, *, project: dict[str, Any] | None = None, site: dict[str, Any] | None = None, settings: Any = None, config: dict[str, str] | None = None) -> Result

Calls method ("parse", "parse/transform/each", "render/transform/each", "render", "render/transform/all" or "initialize") with params. settings are given to the handler as ctx.settings; without them, the plugin's config_files are read from config["dir"] (config is ctx.config: dir and name). project and site are ctx.project (root, source_dir, files) and ctx.site (title, base_url).

function parse #

parse(plugin: Plugin, source: str, text: str, **kwargs: Any) -> Result

Parses text as the file source.

function read #

read(plugin: Plugin, document: dict[str, Any], **kwargs: Any) -> Result

Runs parse/transform/each on document.

function apply #

apply(plugin: Plugin, document: dict[str, Any], collected: Any = None, **kwargs: Any) -> Result

Runs the transformer on document with collected data.

function render #

render(plugin: Plugin, document: dict[str, Any], format: str = "html", **kwargs: Any) -> Result

Renders document to format. output is returned as bytes.

function render_all #

render_all(plugin: Plugin, pages: list[dict[str, Any]], format: str = "html", **kwargs: Any) -> Result

Runs render/transform/all for pages (dicts with source, path and optional metadata and data). Each file's output is returned as bytes.