tests package

Submodules

tests.conftest module

tests.fake_manager module

In-memory package manager for CLI plumbing tests.

Real-manager iteration leaks the host environment into the test suite: a runner without apk skips it, a runner without brew skips it, and assertions about package counts or table rendering become a function of which binaries happen to be on PATH. The FakeManager below sidesteps that by reporting as available on every platform and yielding a fixed catalog of packages without ever invoking a subprocess.

Tests opt in via the fake_pool fixture in tests.conftest, which monkeypatches meta_package_manager.pool.ManagerPool.select_managers() to yield a single fake instead of the real-manager iteration.

class tests.fake_manager.FakeManager[source]

Bases: PackageManager

Always-available manager with deterministic outputs.

Reports as supported on every platform and short-circuits the discovery properties (cli_path, executable, fresh, version) so the pool never tries to introspect a real binary. Subcommand methods yield fixed package sets so tests can assert on counts and ordering.

Initialize cli_errors list.

homepage_url: str | None = 'https://example.invalid/fake-manager'

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

platforms: frozenset[Platform] | Group | Platform | Iterable[Platform | Group] = frozenset({Platform(id='aix', name='IBM AIX'), Platform(id='almalinux', name='AlmaLinux'), Platform(id='alpine', name='Alpine Linux'), Platform(id='altlinux', name='ALT Linux'), Platform(id='amzn', name='Amazon Linux'), Platform(id='android', name='Android'), Platform(id='arch', name='Arch Linux'), Platform(id='buildroot', name='Buildroot'), Platform(id='cachyos', name='CachyOS'), Platform(id='centos', name='CentOS'), Platform(id='chromeos', name='ChromeOS'), Platform(id='clearlinux', name='Clear Linux OS'), Platform(id='cloudlinux', name='CloudLinux OS'), Platform(id='cygwin', name='Cygwin'), Platform(id='debian', name='Debian'), Platform(id='dragonfly_bsd', name='DragonFly BSD'), Platform(id='endeavouros', name='EndeavourOS'), Platform(id='exherbo', name='Exherbo Linux'), Platform(id='fedora', name='Fedora'), Platform(id='freebsd', name='FreeBSD'), Platform(id='generic_linux', name='Generic Linux'), Platform(id='gentoo', name='Gentoo Linux'), Platform(id='guix', name='Guix System'), Platform(id='haiku', name='Haiku'), Platform(id='hurd', name='GNU/Hurd'), Platform(id='ibm_powerkvm', name='IBM PowerKVM'), Platform(id='illumos', name='illumos'), Platform(id='kali', name='Kali Linux'), Platform(id='kvmibm', name='KVM for IBM z Systems'), Platform(id='linuxmint', name='Linux Mint'), Platform(id='macos', name='macOS'), Platform(id='mageia', name='Mageia'), Platform(id='mandriva', name='Mandriva Linux'), Platform(id='manjaro', name='Manjaro Linux'), Platform(id='midnightbsd', name='MidnightBSD'), Platform(id='netbsd', name='NetBSD'), Platform(id='nixos', name='NixOS'), Platform(id='nobara', name='Nobara'), Platform(id='openbsd', name='OpenBSD'), Platform(id='opensuse', name='openSUSE'), Platform(id='openwrt', name='OpenWrt'), Platform(id='oracle', name='Oracle Linux'), Platform(id='os400', name='IBM i'), Platform(id='parallels', name='Parallels'), Platform(id='pidora', name='Pidora'), Platform(id='pikaos', name='PikaOS'), Platform(id='raspbian', name='Raspbian'), Platform(id='rhel', name='RedHat Enterprise Linux'), Platform(id='rocky', name='Rocky Linux'), Platform(id='scientific', name='Scientific Linux'), Platform(id='slackware', name='Slackware'), Platform(id='sles', name='SUSE Linux Enterprise Server'), Platform(id='slitaz', name='SliTaz GNU/Linux'), Platform(id='solaris', name='Solaris'), Platform(id='sourcemage', name='Source Mage GNU/Linux'), Platform(id='sunos', name='SunOS'), Platform(id='tuxedo', name='Tuxedo OS'), Platform(id='ubuntu', name='Ubuntu'), Platform(id='ultramarine', name='Ultramarine'), Platform(id='void', name='Void Linux'), Platform(id='windows', name='Windows'), Platform(id='wsl1', name='Windows Subsystem for Linux v1'), Platform(id='wsl2', name='Windows Subsystem for Linux v2'), Platform(id='xenserver', name='XenServer')})

List of platforms supported by the manager.

Allows for a mishmash of platforms and groups of platforms. Will be normalized into a frozenset of Platform instances at instantiation.

cli_names: tuple[str, ...] = ('fake-mpm',)

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).

requirement: str | None = '>=0'

Version requirement specifier.

Supports a comma-separated range of constraints (e.g. ">=1.20.0,<2.0.0"). A bare version string like "1.20.0" is treated as >=1.20.0.

Parsed by meta_package_manager.version.VersionRange.

Defaults to None, which deactivates version check entirely.

property cli_path: Path

Fully qualified path to the canonical package manager binary.

Try each CLI names provided by cli_names, in each system path provided by cli_search_path. In that order. Then returns the first match.

Executability of the CLI will be separately assessed later by the meta_package_manager.execution.CLIExecutor.executable property below.

property executable: bool

Is the package manager CLI can be executed by the current user?

property fresh: bool

Does the package manager match the version requirement?

property version: TokenizedString | None

Invoke the manager and extract its own reported version string.

Returns a parsed and normalized version in the form of a meta_package_manager.version.TokenizedString instance.

Skipped on platforms where the manager is not supported, even if cli_path resolved to an executable: that binary almost certainly belongs to a different tool that happens to share the same name (e.g. GNU make on macOS getting matched by the FreeBSD ports manager), so probing it would either misreport the version or surface confusing error output.

property installed: Iterator[Package]

List packages currently installed on the system.

Optional. Will be simply skipped by mpm if not implemented.

property outdated: Iterator[Package]

List installed packages with available upgrades.

Optional. Will be simply skipped by mpm if not implemented.

property orphans: Iterator[Package]

List packages installed as dependencies that nothing requires anymore.

The read-only counterpart of the --orphans action flags: where mpm cleanup --orphans removes the orphans, this query only reports them, through the manager’s native listing (pacman --query --deps --unrequired, brew autoremove --dry-run, dnf repoquery --unneeded, …). mpm builds no dependency graph: the manager decides what is orphaned.

Optional. Will be simply skipped by mpm if not implemented.

search(query, extended, exact)[source]

Search packages available for install.

There is no need for this method to be perfect and sensitive to extended and exact parameters. If the package manager is not supporting these kind of options out of the box, just returns the closest subset of matching package you can come up with. Finer refiltering will happens in the meta_package_manager.manager.PackageManager.refiltered_search() method below.

Optional. Will be simply skipped by mpm if not implemented.

Return type:

Iterator[Package]

upgrade_all_cli()[source]

Static upgrade CLIs declare the upgrade capabilities.

Never invoked by meta_package_manager.bar_plugin_renderer.BarPluginRenderer.add_upgrade_cli(), which routes menu actions through mpm itself, but their presence is what makes meta_package_manager.capabilities.implements() report the upgrade and upgrade_all operations as supported, so the fake manager’s menu lines carry an action.

Return type:

tuple[str, ...]

upgrade_one_cli(package_id, version=None)[source]

Returns the complete CLI to upgrade one package and one only.

Allows a specific version to be provided.

Return type:

tuple[str, ...]

id: str = 'fakemanager'

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 = 'FakeManager'

Return package manager’s common name.

Default value is based on class name.

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.

class tests.fake_manager.TimingOutFakeManager[source]

Bases: FakeManager

Variant that runs a real subprocess long enough to trip --timeout.

Used by tests.test_cli.test_timeout() to exercise the subprocess.TimeoutExpired branch in meta_package_manager.execution.CLIExecutor.run(). The Python interpreter is invoked as the manager’s CLI so the test stays cross-platform; the sleep duration is derived from timeout so the call is guaranteed to overshoot.

Initialize cli_errors list.

property outdated: Iterator[Package]

List installed packages with available upgrades.

Optional. Will be simply skipped by mpm if not implemented.

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

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).

id: str = 'timingoutfakemanager'

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 = 'TimingOutFakeManager'

Return package manager’s common name.

Default value is based on class name.

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.

tests.test_bar_plugin module

tests.test_brewfile module

tests.test_cli module

tests.test_cli_backup module

tests.test_cli_dump module

mpm dump CLI tests.

Drives the subcommand against the deterministic fake_pool. The Brewfile renderer it delegates to is unit-tested in tests.test_brewfile, and the snapshot/merge/update flows shared with the backup alias live in tests.test_cli_backup.

tests.test_cli_dump.test_dump_query_filter_narrows_to_matches(invoke, fake_pool)[source]

dump --query keeps only installed packages matching the query.

tests.test_cli_dump.test_dump_without_query_lists_all(invoke, fake_pool)[source]

Without a query, dump snapshots the full installed inventory.

tests.test_cli_install_remove module

tests.test_cli_installed module

tests.test_cli_managers module

tests.test_cli_orphans module

tests.test_cli_outdated module

tests.test_cli_restore module

tests.test_cli_sbom module

tests.test_cli_search module

tests.test_cli_upgrade module

tests.test_cli_which module

tests.test_cooldown module

tests.test_dispatch module

tests.test_docs module

tests.test_docstring_corpus module

tests.test_doctor module

tests.test_execution module

tests.test_gnome_extension module

tests.test_help module

tests.test_manager_apt module

tests.test_manager_definition module

tests.test_manager_homebrew module

tests.test_manager_mas module

tests.test_manager_mise module

tests.test_manager_overrides module

tests.test_manager_pip module

tests.test_manager_pipx module

tests.test_manager_uv module

tests.test_manager_winget module

tests.test_managers module

tests.test_metadata module

tests.test_orphans module

tests.test_pool module

tests.test_sbom module

tests.test_sbom_vulnerabilities module

tests.test_specifier module

tests.test_sphinx_crossrefs module

tests.test_sudo module

tests.test_version module