tests.test_docstring_corpus module

Replay documented CLI output back through each manager’s own parser.

Every query method documents a sample invocation and its output in a MyST {code-block} shell-session fence sitting right next to the regex (or JSON parser) that consumes it. This module feeds each harvested block back through the parser it illustrates, asserting the documented example still yields well-formed packages. The harvesting itself lives in meta_package_manager.docstring_corpus, shared with the reference-traces documentation generator.

It is a Tier-1 guard: it proves the documented output still parses (which catches a regex that silently stops matching after an upstream format change, or a docstring that has drifted from the code beside it), not that every field is captured correctly. It authors no fixtures of its own: the corpus is the docstrings.

It covers installed, outdated, orphans, search and --version blocks. installed, orphans and --version are single-source (one CLI call), fed straight through. outdated may cross-reference two commands (list + latest), so its calls are routed to the right block by a command-dispatching stub. Every shell-session block of these members is a complete fixture that must parse: illustrations (a human-readable variant, an interactive prompt, a narrative) live in a non-harvested console fence instead. See https://github.com/kdeldycke/meta-package-manager/issues/1023.

tests.test_docstring_corpus.PROBE_CACHES = ('version_output', 'version')

Cached properties of the version probe, dropped around each stubbed probe.

tests.test_docstring_corpus.test_documented_output_still_parses(manager, member, output, monkeypatch, stub_run_cli)[source]

The output documented next to a parser must still parse through it.

tests.test_docstring_corpus.test_documented_ids_read_back_from_their_purl(manager, member, output, monkeypatch)[source]

Every documented package ID reads back from the pURL of a menu action.

A menu action passes that pURL to mpm upgrade, and the ID reads back tied to the same manager.

tests.test_docstring_corpus.MANAGERS_BREAKING_THEIR_PURL_TYPE = frozenset({'apk', 'cpan', 'julia'})

The managers whose ID is a registered pURL type that their package IDs break.

The apk manager names a package without its vendor, the cpan manager names a Perl module instead of its distribution, and the julia manager names a package without its UUID. Specifier.parse_purl() reads their pURLs anyway.

tests.test_docstring_corpus.test_documented_purls_follow_their_registered_type(manager, member, output, monkeypatch)[source]

The pURL of each documented package follows the rules of its registered type.

That pURL takes the manager ID as its type, so the rules apply when the ID is a registered type.

tests.test_docstring_corpus.test_display_blocks_align_with_raw()[source]

The compiled and raw harvests agree on structure.

The compiled harvest is what the docs render, the raw one what this test replays.

meta_package_manager/_docs.py selects reference-trace blocks by (member, index) from class_display_blocks(), while this test replays the same blocks from class_blocks(). Their per-member block counts must match, or an index would point at a different block on the two sides.

tests.test_docstring_corpus.test_fixtures_carry_no_truncation_marker()[source]

A harvested fixture block must document its output in full.

installed/outdated/orphans/search/version_regexes blocks are complete samples, so none may abbreviate its output with a (...) marker (an illustration that would truncate belongs under a non-harvested console fence). A bare ... is left alone: real CLI output legitimately contains it, like apt’s Listing... header or a guix store path.

tests.test_docstring_corpus.test_query_fixtures_run_verbatim()[source]

A harvested query fixture must show the exact command mpm runs.

installed/outdated/orphans/version_regexes invocations go through run_cli, which executes an argv directly with no shell, so a documented command joined to another by a shell pipe (| jq to pretty-print JSON, echo n | to feed an interactive prompt) shows an invocation mpm never makes and would render a misleading reference trace. Such a block is an illustration and belongs under a non-harvested console fence.

Re-tokenized with shlex.split() like _documented_commands does for the mutation members, so a pipe inside a quoted argument (PowerShell’s -Command "... | ...", which mpm passes as a single token for pwsh to run internally) stays one token and is not a shell pipe at mpm’s level.

tests.test_docstring_corpus.MUTATION_MEMBERS = ('cleanup_cache', 'cleanup_orphan', 'cleanup_repair', 'doctor_cli', 'install', 'mark_explicit', 'remove', 'remove_orphan', 'search', 'sync', 'upgrade_all_cli', 'upgrade_one_cli')

Methods whose docstrings document the exact CLI they run.

tests.test_docstring_corpus.PID_SENTINEL = 'MPM-DOC-SENTINEL'

Stand-in package id; the documented command carries a real example id where the constructed command carries this.

tests.test_docstring_corpus.BUILD_CLI_KWARGS = frozenset({'auto_post_args', 'auto_pre_args', 'auto_pre_cmds', 'override_cli_path', 'override_post_args', 'override_pre_args', 'override_pre_cmds'})

run_cli kwargs forwarded to build_cli when reconstructing the full command. sudo is deliberately not forwarded: escalation depends on platform and policy, so documented sudo prefixes are stripped on the other side.

tests.test_docstring_corpus.PLACEHOLDER_RE = re.compile('^\\{[a-z][a-z0-9-]*\\}$')

A documented token standing in for one the docstring cannot spell out.

Two kinds earn one, and nothing else does. A value that cannot be written on a command line at all, like the dnf --qf format ending in a real newline. And a value resolved at run time from an earlier call, like the go binary directory or the yarn global directory, where a concrete example would pin the docstring to whichever machine produced it. Every other token is written verbatim, which is what lets test_documented_query_command_matches_construction() read the rest of a command as an exact record. Braces follow the placeholder convention this project already uses for shell examples.

tests.test_docstring_corpus.test_documented_command_matches_construction(manager, member, documented, monkeypatch)[source]

The command a mutation docstring shows must be the one the method builds.

A shell-session fence is no proof of verification on its own. _documented_commands reads a command holding && or a pipe as an illustration and skips it, so a mutation block written as a shell line (cd {dir} && make install) sits in the corpus unchecked. Give such a block the console fence. Where the argv cannot be rebuilt from a stand-in package ID, as for Ports.install which resolves its origin by query, the docstring says so.

tests.test_docstring_corpus.QUERY_MEMBERS = ('installed', 'orphans', 'outdated')

Read-only members whose docstrings document the exact CLI they run.

test_documented_output_still_parses() replays their documented output through the parser, which proves the sample still parses. That says nothing about whether the command producing it is still the one the code sends. An argument that reshapes output rather than merely quieting it drifts the two apart in silence, leaving a fixture that parses beside a system that answers nothing, which is how emerge’s --quiet went unnoticed.

tests.test_docstring_corpus.test_documented_query_command_matches_construction(manager, member, documented, monkeypatch)[source]

The command a query docstring shows must be the one the member builds.