tests.test_cli_install_remove module

mpm install and mpm remove CLI tests.

The two operations are siblings, so they share one module.

class tests.test_cli_install_remove.SearchlessFakeManager[source]

Bases: ChangingFakeManager

A changing fake with no search operation.

Initialize cli_errors list.

search(query, extended, exact)[source]

Find any package, so an install left untied reaches its attempt.

cli_names: tuple[str, ...] = ('searchlessfakemanager',)

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

documentation_url: str | None = None

Entry point of the project’s own documentation, or None when it has none.

The manual, the documentation site, or the man page of the CLI mpm drives: whichever page a user reads to learn the commands this manager wraps. Listed between homepage_url and repository_url in the links of the manager’s page, so a reader reaching for the tool’s reference finds it in the box of facts rather than in the prose below it.

Left unset where a link would state a fact twice or invent one: a tool documenting itself in its repository alone, whose README repository_url already reaches. A page about the ecosystem rather than the tool does not qualify either.

Where a project’s only site is its manual, that address belongs here and homepage_url stays unset: the slot names what the page is, and a reader reaching for the reference looks under the documentation link.

Never inherited, like every other link: the AUR helpers extending pacman each document themselves.

homepage_url: str | None = None

Home page of the project, only used in documentation for reference.

Left unset when the home page is the project’s repository, which repository_url names on its own, and when it is the project’s manual, which documentation_url names. Never inherited, like the other links.

id: str = 'searchlessfakemanager'

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'SearchlessFakeManager'

Return package manager’s common name.

Default value is based on class name.

repository_url: str | None = None

Repository holding the project’s code, or None when it has no public one.

Linked from the manager’s documentation page. Also what the weekly metrics sample reads: docs/docs_update.py writes it into the [tool.repomatic.metrics] subjects of pyproject.toml when its forge answers the sampler, through a mirror for a forge that does not.

Never inherited, for the same reason as wikipedia_url: the AUR helpers extending pacman each live in a repository of their own.

virtual: bool = False

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

wikipedia_url: str | None = None

English Wikipedia article about the project, or None when it has none.

Listed last in the links of the manager’s documentation page. The article covers the project that home page names, or is a redirect Wikipedia keeps under the project’s name, landing on the part of a broader article that describes it: Cargo_(software) opens the Cargo section of the Rust article. An article that merely mentions the project does not count, nor does one about a related subject: lazy is a Neovim plugin manager, and the Neovim article is not about it.

Never inherited: the metaclass resets it to None on any class not declaring its own. A subclass often wraps a distinct project, like the six AUR helpers extending pacman, and would otherwise present pacman’s article as its own. Documentation-only, like homepage_url.

class tests.test_cli_install_remove.UnsearchableFakeManager[source]

Bases: ChangingFakeManager

A changing fake whose search command fails.

Initialize cli_errors list.

search(query, extended, exact)[source]

Find any package, so an install left untied reaches its attempt.

cli_names: tuple[str, ...] = ('unsearchablefakemanager',)

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

documentation_url: str | None = None

Entry point of the project’s own documentation, or None when it has none.

The manual, the documentation site, or the man page of the CLI mpm drives: whichever page a user reads to learn the commands this manager wraps. Listed between homepage_url and repository_url in the links of the manager’s page, so a reader reaching for the tool’s reference finds it in the box of facts rather than in the prose below it.

Left unset where a link would state a fact twice or invent one: a tool documenting itself in its repository alone, whose README repository_url already reaches. A page about the ecosystem rather than the tool does not qualify either.

Where a project’s only site is its manual, that address belongs here and homepage_url stays unset: the slot names what the page is, and a reader reaching for the reference looks under the documentation link.

Never inherited, like every other link: the AUR helpers extending pacman each document themselves.

homepage_url: str | None = None

Home page of the project, only used in documentation for reference.

Left unset when the home page is the project’s repository, which repository_url names on its own, and when it is the project’s manual, which documentation_url names. Never inherited, like the other links.

id: str = 'unsearchablefakemanager'

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'UnsearchableFakeManager'

Return package manager’s common name.

Default value is based on class name.

repository_url: str | None = None

Repository holding the project’s code, or None when it has no public one.

Linked from the manager’s documentation page. Also what the weekly metrics sample reads: docs/docs_update.py writes it into the [tool.repomatic.metrics] subjects of pyproject.toml when its forge answers the sampler, through a mirror for a forge that does not.

Never inherited, for the same reason as wikipedia_url: the AUR helpers extending pacman each live in a repository of their own.

virtual: bool = False

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

wikipedia_url: str | None = None

English Wikipedia article about the project, or None when it has none.

Listed last in the links of the manager’s documentation page. The article covers the project that home page names, or is a redirect Wikipedia keeps under the project’s name, landing on the part of a broader article that describes it: Cargo_(software) opens the Cargo section of the Rust article. An article that merely mentions the project does not count, nor does one about a related subject: lazy is a Neovim plugin manager, and the Neovim article is not about it.

Never inherited: the metaclass resets it to None on any class not declaring its own. A subclass often wraps a distinct project, like the six AUR helpers extending pacman, and would otherwise present pacman’s article as its own. Documentation-only, like homepage_url.

class tests.test_cli_install_remove.HeldFakeManager[source]

Bases: ChangingFakeManager

A changing fake whose packages the cooldown holds back.

Initialize cli_errors list.

cooldown_hold(package_id)[source]

Decide whether the release-age cooldown holds back one package.

The per-package half of the gate, for managers that implement the release_date() probe instead of carrying a native cooldown_env_var. Returns None when the package may proceed: no active probe-backed cooldown, or a publication old enough to clear the window. Returns a CooldownHold otherwise: the caller logs its reason, and the change report reads its two timestamps.

The probe is fail-closed: a publication date that cannot be read (probe failure, or a registry carrying no date) holds the package under the default enforce posture, and only a best-effort policy lets it through, unguarded.

A package is probed once per invocation, and its verdict reused after that: the command that acts on a verdict and the report that closes it read the same one, whatever the clock did in between.

cli_names: tuple[str, ...] = ('heldfakemanager',)

List of CLI names the package manager is known as.

This list of recognized CLI names is ordered by priority. That way we can influence the search of the right binary.

..hint::

This was helpful in the case of the Python transition from 2.x to 3.x, where multiple versions of the same executable were named python or python3.

By default, this property’s value is derived from the manager’s ID (see the MetaPackageManager.__init__ method above).

documentation_url: str | None = None

Entry point of the project’s own documentation, or None when it has none.

The manual, the documentation site, or the man page of the CLI mpm drives: whichever page a user reads to learn the commands this manager wraps. Listed between homepage_url and repository_url in the links of the manager’s page, so a reader reaching for the tool’s reference finds it in the box of facts rather than in the prose below it.

Left unset where a link would state a fact twice or invent one: a tool documenting itself in its repository alone, whose README repository_url already reaches. A page about the ecosystem rather than the tool does not qualify either.

Where a project’s only site is its manual, that address belongs here and homepage_url stays unset: the slot names what the page is, and a reader reaching for the reference looks under the documentation link.

Never inherited, like every other link: the AUR helpers extending pacman each document themselves.

homepage_url: str | None = None

Home page of the project, only used in documentation for reference.

Left unset when the home page is the project’s repository, which repository_url names on its own, and when it is the project’s manual, which documentation_url names. Never inherited, like the other links.

id: str = 'heldfakemanager'

Package manager’s ID.

Derived by defaults from the lower-cased class name in which underscores _ are replaced by dashes -.

This ID must be unique among all package manager definitions and lower-case, as they’re used as feature flags for the mpm CLI.

name: str = 'HeldFakeManager'

Return package manager’s common name.

Default value is based on class name.

repository_url: str | None = None

Repository holding the project’s code, or None when it has no public one.

Linked from the manager’s documentation page. Also what the weekly metrics sample reads: docs/docs_update.py writes it into the [tool.repomatic.metrics] subjects of pyproject.toml when its forge answers the sampler, through a mirror for a forge that does not.

Never inherited, for the same reason as wikipedia_url: the AUR helpers extending pacman each live in a repository of their own.

virtual: bool = False

Should we expose the package manager to the user?

Virtual package manager are just skeleton classes used to factorize code among managers of the same family.

wikipedia_url: str | None = None

English Wikipedia article about the project, or None when it has none.

Listed last in the links of the manager’s documentation page. The article covers the project that home page names, or is a redirect Wikipedia keeps under the project’s name, landing on the part of a broader article that describes it: Cargo_(software) opens the Cargo section of the Rust article. An article that merely mentions the project does not count, nor does one about a related subject: lazy is a Neovim plugin manager, and the Neovim article is not about it.

Never inherited: the metaclass resets it to None on any class not declaring its own. A subclass often wraps a distinct project, like the six AUR helpers extending pacman, and would otherwise present pacman’s article as its own. Documentation-only, like homepage_url.

tests.test_cli_install_remove.subcmd()[source]
tests.test_cli_install_remove.evaluate_signals(mid, stdout, stderr)[source]
tests.test_cli_install_remove.check_selection(result, selected=('am', 'antidote', 'antigen', 'antigravity-cli-plugins', 'apk', 'app-manager', 'apt', 'apt-mint', 'aptitude', 'asdf', 'aura', 'basalt', 'bin', 'bob', 'bpkg', 'brew', 'bun', 'cargo', 'choosenim', 'claude-code-plugins', 'clib', 'composer', 'conda', 'cpan', 'cran', 'deb-get', 'dkp-pacman', 'dnf', 'dnf5', 'dotnet', 'elan', 'emacs', 'emerge', 'eopkg', 'fisher', 'flatpak', 'fwupd', 'gcloud', 'gem', 'getnf', 'gext', 'gh-ext', 'ghcup', 'go', 'guix', 'gup', 'haxelib', 'hyprpm', 'jpm', 'julia', 'juliaup', 'krew', 'lazy', 'luarocks', 'lure', 'mamba', 'mason', 'micro', 'microdnf', 'micromamba', 'miktex', 'mise', 'nala', 'nimble', 'nix', 'npm', 'octave', 'oh-my-fish', 'ollama', 'opam', 'opkg', 'pacman', 'pacstall', 'pamac', 'paru', 'pear', 'pearl', 'pi', 'pikaur', 'pip', 'pipx', 'pipxu', 'pixi', 'pkcon', 'pkgit', 'pkgm', 'platformio-core', 'pmerge', 'pnpm', 'protonplus', 'pwsh-gallery', 'pyenv', 'raco', 'roswell', 'rpm-ostree', 'rustup', 'sdkman', 'sheldon', 'skills', 'snap', 'soar', 'spack', 'steamcmd', 'stew', 'tlmgr', 'topgrade', 'trizen', 'uv', 'uvx', 'vagrant', 'vcpkg', 'vim-pack', 'vscode', 'vscodium', 'whalebrew', 'xbps', 'yarn', 'yarn-berry', 'yay', 'yazi', 'yum', 'zef', 'zerobrew', 'zeroinstall', 'zim', 'zinit', 'zplug', 'zvm', 'zypper'), reference_set=('am', 'antidote', 'antigen', 'antigravity-cli-plugins', 'apk', 'app-manager', 'apt', 'apt-mint', 'aptitude', 'asdf', 'aura', 'basalt', 'bin', 'bob', 'bpkg', 'brew', 'bun', 'cargo', 'choosenim', 'claude-code-plugins', 'clib', 'composer', 'conda', 'cpan', 'cran', 'deb-get', 'dkp-pacman', 'dnf', 'dnf5', 'dotnet', 'elan', 'emacs', 'emerge', 'eopkg', 'fisher', 'flatpak', 'fwupd', 'gcloud', 'gem', 'getnf', 'gext', 'gh-ext', 'ghcup', 'go', 'guix', 'gup', 'haxelib', 'hyprpm', 'jpm', 'julia', 'juliaup', 'krew', 'lazy', 'luarocks', 'lure', 'mamba', 'mason', 'micro', 'microdnf', 'micromamba', 'miktex', 'mise', 'nala', 'nimble', 'nix', 'npm', 'octave', 'oh-my-fish', 'ollama', 'opam', 'opkg', 'pacman', 'pacstall', 'pamac', 'paru', 'pear', 'pearl', 'pi', 'pikaur', 'pip', 'pipx', 'pipxu', 'pixi', 'pkcon', 'pkgit', 'pkgm', 'platformio-core', 'pmerge', 'pnpm', 'protonplus', 'pwsh-gallery', 'pyenv', 'raco', 'roswell', 'rpm-ostree', 'rustup', 'sdkman', 'sheldon', 'skills', 'snap', 'soar', 'spack', 'steamcmd', 'stew', 'tlmgr', 'topgrade', 'trizen', 'uv', 'uvx', 'vagrant', 'vcpkg', 'vim-pack', 'vscode', 'vscodium', 'whalebrew', 'xbps', 'yarn', 'yarn-berry', 'yay', 'yazi', 'yum', 'zef', 'zerobrew', 'zeroinstall', 'zim', 'zinit', 'zplug', 'zvm', 'zypper'), strict_selection_match=True, *, signals=<function evaluate_signals>)

Selection assertions reading this subcommand’s own signals.

tests.test_cli_install_remove.test_no_package_id(invoke, operation)[source]
tests.test_cli_install_remove.test_install_unresolved_exits_nonzero(invoke, fake_pool)[source]

install exits non-zero when no manager can provide the requested package.

Guards against a regression where a failed install was swallowed and the command still exited 0 (see the install command in cli.py).

tests.test_cli_install_remove.test_install_unresolved_zero_exit_opt_out(invoke, fake_pool, flag)[source]

-0/–zero-exit keeps the exit code at 0 on per-package failures.

The critical summary stays as the durable record.

tests.test_cli_install_remove.test_remove_absent_package_is_idempotent(invoke, fake_pool)[source]

Removing a package no manager has installed is a no-op, not a failure.

remove only fails when a manager that has the package fails to remove it.

tests.test_cli_install_remove.test_remove_with_manager_lacking_inventory(invoke, create_config, tmp_path)[source]

A package handed to a lone manager keeping no inventory reaches its remove.

sheldon implements remove but no installed, so no lookup can find a package in it. The lookup selecting the managers implementing installed exited the command on its empty selection, and past that the package was skipped as unrecognized.

tests.test_cli_install_remove.test_install_reports_what_moved(invoke, changing_fake_pool)[source]

A package tied to its manager installs on the concurrent path.

The report names it with the dependency it pulled in.

tests.test_cli_install_remove.test_install_untied_reports_every_attempt(invoke, changing_fake_pool)[source]

Packages left untied install through the sequential priority search.

Its manager opens once, so the report keeps the first install too.

tests.test_cli_install_remove.test_failed_install_names_its_cause_on_the_trail(invoke, changing_fake_pool, monkeypatch, spec, detail)[source]

The ✘ line of a failed install names the cause its error carries.

Both install paths do: the concurrent one a tied package takes, and the sequential priority search of an untied one. A failure with no known cause keeps a bare line, the glyph saying enough.

tests.test_cli_install_remove.test_dry_run_install_names_plan(invoke, changing_fake_pool, queries_through_a_cli)[source]

A simulated search finds nothing, which is no proof the package is missing.

tests.test_cli_install_remove.test_plan_install_resolves_what_dry_run_cannot(invoke, changing_fake_pool, queries_through_a_cli)[source]

The control: --plan runs the search, so the same package resolves.

tests.test_cli_install_remove.test_install_report_serialized_keeps_the_exit_code(invoke, changing_fake_pool)[source]

The serialized report prints, and a failed package still exits non-zero.

tests.test_cli_install_remove.test_install_ties_and_searches_in_one_run(invoke, changing_fake_pool)[source]

A run holding both kinds installs the tied package first.

Then it searches for the untied one.

tests.test_cli_install_remove.test_install_without_search_tries_the_package_directly(invoke, patch_pool_with)[source]

A manager with no search operation still gets the install attempt.

The next manager never runs.

A search that fails counts as a miss: the next manager gets its turn.

tests.test_cli_install_remove.test_install_stops_at_a_cooldown_hold(invoke, patch_pool_with)[source]

A held package ends the search at the first manager providing it.

The next manager would sidestep the hold. A hold is no failure, so the run exits 0.

An exact search answering two packages stops the install.

It is a bug of the manager, and the install does not pick one of them.

tests.test_cli_install_remove.test_remove_reports_what_moved(invoke, changing_fake_pool, args, removed)[source]

The report names the removed package, and the orphan its cascade took.

tests.test_cli_install_remove.test_single_manager_install_and_remove(invoke, manager_id, package_id)[source]

Test the installation and removal of a package with each manager.

Caution

strict_selection_match is set to False because the install subcommand will not try all managers selected by default. So a strict match is not possible.

That’s because install subcommand try each user-selected manager until it find one providing the package we seek to install, after which the process stop.

Note

Managers that cannot complete a real install in a given environment are not skipped: they are listed in INSTALL_REMOVE_BLOCKED_WHEN (destructive_plan.py) and driven anyway. The blocked install is capped at SHORT_FAILURE_TIMEOUT and asserted to fail the stable mpm way (exit 1 plus a Could not install:` message). It runs at `--verbosity INFO: the minimum level at which the Installation priority dispatch signal is visible (the default WARNING would hide it and make check_manager_selection() pass vacuously). No follow-up remove: the failed install left nothing to remove, and the working managers already cover the removal path.

A manager in REMOVE_REFUSES_INSTALLED is the other way round: its install succeeds and its remove is refused on purpose, so both legs run and the refusal is asserted rather than a clean exit.

tests.test_cli_install_remove.test_collection_hook_runs_before_xdist_stamps_the_group()[source]

mpm’s collection hook must run before xdist’s, or the groups do nothing.

--dist=loadgroup does not read the xdist_group marker when it schedules: xdist’s own worker-side hook copies the group name onto the node id as an @<group> suffix, and the controller schedules from that. So a marker this suite adds in pytest_collection_modifyitems is only seen if that hook has already run when xdist’s does, and pytest calls the later-registered plugin first: the worker interactor registers after conftest.py, so without tryfirst it stamps ids that carry no group at all.

The failure is silent and platform-shaped, which is why it is guarded here rather than left to CI: nothing errors, the tests simply scatter across workers, and the only symptom is two managers colliding on a backend lock they were supposed to take in turn. apt and aptitude did exactly that on the Ubuntu runners, each reporting the other’s process holding /var/lib/dpkg/lock-frontend.

tests.test_cli_install_remove.test_suite_collects_without_xdist()[source]

The suite collects without pytest-xdist, as a lean packager build runs it.

strict_markers fails collection on any marker nothing declares, and only pytest-xdist declares the xdist_group marker this suite sets. So conftest.py declares it as well whenever the plugin is not loaded.

tests.test_cli_install_remove.test_loadgroup_keeps_a_group_on_one_worker(tmp_path)[source]

--dist=loadgroup must run every test of one xdist_group on one worker.

The test above only orders the hooks: the scheduling itself belongs to pytest-xdist, and a pytest release can break it with no error. Under pytest-xdist 3.8.0, pytest 9.2.0 drops the @<group> suffix from the node IDs, so the groups spread across workers and apt meets aptitude on the dpkg lock. This runs a real session, with no other plugin, to catch such a release.

Todo

Drop the pytest<9.2 cap of the test dependency group once a pytest-xdist release ships pytest-dev/pytest-xdist#1388, which pytest-dev/pytest-xdist#1407 asks for.