tests.test_managers module¶

tests.test_managers.test_xkcd_set()[source]¶
tests.test_managers.test_unmaintained(manager)[source]¶

An unmaintained manager documents itself with unmaintained_message.

The message must be non-empty, and any URL embedded in that markdown message must be a well-formed http(s) link.

Conversely, an unmaintained_message is only meaningful on an unmaintained manager.

tests.test_managers.test_maintenance_note(manager)[source]¶

A maintenance_note is MyST markdown whose URLs are http(s) links.

It is mutually exclusive with the unmaintained flag: a confirmed-dead manager documents itself with an unmaintained_message instead of a watch note.

tests.test_managers.test_operation_notes(manager)[source]¶

Every declared operation note keys a real operation and stays one full sentence.

The Notes column of the manager pages renders each entry verbatim beside its operation row, so a key outside the Operations vocabulary would never reach a page, and a note spanning lines, or not reading as a standalone sentence (no capital to open it, no period to close it, or an opening code span a capital cannot sit on), would break the column’s shape.

tests.test_managers.test_privileged_operations(manager)[source]¶

privileged_operations names exactly the sudo=True operations.

Those are the operations whose methods carry a sudo=True marker.

prime_sudo reads the set to choose the managers of the up-front password prompt. A missing operation lets an escalated command meet a cold cache inside the fan-out, and an extra one asks for a password no command uses. A marker on a method outside METHOD_OPERATIONS belongs to no operation, so it fails the test too. A config-defined manager derives the set from its definition, which is checked against the raw TOML.

tests.test_managers.test_ascii_id(manager)[source]¶

All package manager IDs should be short ASCII strings.

tests.test_managers.test_name(manager)[source]¶

Check all managers have a name.

tests.test_managers.test_unique_names()[source]¶
tests.test_managers.test_user_install_dir_hooks_come_in_pairs(manager)[source]¶

A manager that finds a user directory also lists the packages in it.

refiltered_outdated reads both hooks of user_install_dir: one without the other raises NotImplementedError on the host where the rule applies.

tests.test_managers.test_homepage_url(manager)[source]¶

A home page is optional where the repository stands for it.

tests.test_managers.test_repository_url(manager)[source]¶

A repository is optional, since proprietary tools have none.

tests.test_managers.test_documentation_url(manager)[source]¶

A documentation link is optional, and always a page of its own.

A tool documenting itself in its repository README alone declares none, the repository link already reaching it, and neither does a project whose home page is its manual. What is declared names the tool, so an article about it stays in wikipedia_url, and every link is served over TLS.

tests.test_managers.URL_ATTRIBUTES = ('documentation_url', 'homepage_url', 'repository_url', 'wikipedia_url')¶

Every link attribute a manager may declare, found by name rather than listed.

tests.test_managers.test_url_attributes_are_distinct(manager)[source]¶

Check a manager’s links each point somewhere the others do not.

A home page that is the repository is declared once, as repository_url: stating it twice links the same page twice from the manager’s card, under two labels. Every link belongs to the class declaring it, never inherited, since a subclass often wraps a project of its own.

tests.test_managers.DOCUMENTATION_LABEL = re.compile('^Documentation:', re.MULTILINE)¶

A Documentation: label opening a line of a manager docstring.

The address of a markdown link, balanced parentheses included.

Check a docstring states no link its card already carries.

The manager’s page opens on its card, which links every *_url attribute, the documentation entry point among them. A Documentation: line therefore has nothing left to name, and a prose link to an address the card holds states it twice on one page. A further reference keeps its own sentence, unlabelled, the way the command-equivalence tables do.

tests.test_managers.test_platforms(manager)[source]¶

Check platforms is normalized as a frozenset.

tests.test_managers.test_requirement(manager)[source]¶

Each manager is required to specify a version requirement or None.

tests.test_managers.test_cli_names_type(manager)[source]¶

Check the pointed CLI name and path are file-system compatible.

tests.test_managers.test_cli_search_path(manager)[source]¶
tests.test_managers.test_extra_env_type(manager)[source]¶

Check that definitions declare environment variables as a dict of strings.

tests.test_managers.test_global_args_type(manager)[source]¶

Check that definitions returns CLI args as a list of non-empty strings.

tests.test_managers.test_version_cli_options(manager)[source]¶

Version CLI options must be a list of non empty strings.

tests.test_managers.test_version_regexes(manager)[source]¶

Version regex is required.

Check it compiles and match has a <version> group.

tests.test_managers.test_version_regex_matches_sample(manager_id, sample_output, expected_version)[source]¶

Each manager’s version_regexes parses the documented --version output.

Regression guard for the case where re.VERBOSE silently swallowed literal spaces in patterns like guix \(GNU Guix\) ..., leaving the manager unable to detect its own version.

tests.test_managers.EOPKG_LISTING = 'Package Name          |St|        Version|  Rel.|  Distro|             Date\n===========================================================================\naalib                 | i|        1.4.0_5|     9|   Solus|07 Sep 2026 10:08\nzram-generator-defaults  | i|          1.2.1|     7|   Solus|07 Sep 2026 10:09\nzstd                  | i|          1.5.7|    33|   Solus|07 Sep 2026 10:09\nzxing-cpp             | i|          2.3.0|     6|   Solus|07 Sep 2026 10:09\n'¶

A four-package eopkg listing, header and === separator included.

zram-generator-defaults overflows the first column, pushing its pipe right, and the last line is a package rather than a footer.

tests.test_managers.test_eopkg_listing_keeps_its_last_rows(member, stub_run_cli)[source]¶

eopkg’s listings carry no footer, so no trailing line may be discarded.

Both listings used to drop the last two lines before matching, on the assumption of a footer eopkg never prints: its final line is a package. The two packages closing every listing were therefore lost, silently and with a zero exit, so an inventory looked complete while missing its tail.

This guard is narrower than the bug class it comes from, and deliberately so: what a parser may discard can only be read from the tool’s own output, not derived from the manager class. It pins the one listing shape measured against eopkg 4.4.0 and 5.0.0.

tests.test_managers.test_eopkg_installed_reports_the_bare_version(stub_run_cli)[source]¶

installed reports the Version column alone, release excluded.

Every snapshot carries this string, so the release stays out of it. Only outdated pairs the two, where a release-only rebuild would otherwise read as the same version on both sides.

tests.test_managers.test_eopkg_outdated_joins_the_upgrade_candidate(monkeypatch)[source]¶

outdated pairs the installed listing with the candidate info reports.

list-upgrades --install-info describes each package as installed, so the upgrade target appears nowhere in it. The target comes from a second call, info taking every name at once. Both sides carry the release, or the aalib row below (a release-only rebuild) would read 1.4.0_5 on each side and look like no upgrade at all.

tests.test_managers.test_eopkg_candidate_regex_reads_real_info_output(label, info_output, expected)[source]¶

The candidate pattern runs against eopkg info output captured verbatim.

Both blocks come off a Solus 4.9 host. The second is the one that matters: an installed package prints an Installed package: section whose Name : line is shaped exactly like the repository one, so a pattern keyed on the field name alone would report the installed version as the upgrade target. Exactly one match must come back, and it must be the repository’s.

tests.test_managers.test_eopkg_outdated_skips_the_info_call_when_nothing_is_outdated(monkeypatch)[source]¶

An empty listing must not reach info, which prints help with no names.

tests.test_managers.test_eopkg_search_decodes_character_references(stub_run_cli)[source]¶

eopkg search emits the index’s raw summary, character references included.

list-available resolves the same text, so the two disagree on the very same package: only search reaches a user through mpm, and it used to show ImageMagick&#xAE; suite where every other listing says ImageMagick® suite`. Measured against eopkg``4.4.0`.

tests.test_managers.test_parsed_output_omits_reshaping_arg(manager_id, member, forbidden_arg, monkeypatch)[source]¶

An operation whose output feeds a regex must not send a reshaping argument.

Some arguments do not only trim noise, they change the shape of what the tool prints. emerge --quiet is one: --search drops to a bare *  category/name line without the Latest version available: and Description: fields, and --update --columns drops the [ebuild   U  ] state prefix and the brackets around the latest version. Every regex then matches nothing, and the operation reports an empty set on a system that has results, exiting zero with no diagnostic.

Verified against Portage 3.0.81.3. This guard is deliberately narrow: it names the arguments already known to reshape output rather than deriving them, because whether an argument is safe can only be read from the tool’s output, not from the manager class.

It is not made redundant by test_documented_query_command_matches_construction(), which compares a docstring against the argv beside it: adding a reshaping argument to the code and to the docstring leaves those two agreeing, and only this test still fails. An agreement holds whichever way both sides move.

tests.test_managers.test_cli_path(manager)[source]¶
tests.test_managers.test_query_parts(query, query_parts)[source]¶
tests.test_managers.test_package_matches(pkg_id, pkg_name, query, extended, exact, expected)[source]¶
tests.test_managers.CANONICAL_ATTRS = ('scope', 'unmaintained', 'unmaintained_message', 'maintenance_note', 'operation_notes', 'id', 'name', 'homepage_url', 'documentation_url', 'repository_url', 'wikipedia_url', 'logo', 'keywords', 'brewfile_entry_type', 'brewfile_skip_warning', 'platforms', 'virtual', 'sudo', 'default_sudo', 'internal_sudo', 'internal_sudo_operations', 'resets_sudo_timestamp', 'privileged_operations', 'requirement', 'cooldown_env_var', 'cli_names', 'cli_search_path', 'extra_env', 'pre_cmds', 'pre_args', 'post_args', 'operation_extra_args', 'version_cli', 'version_cli_options', 'version_regexes', 'version_from_stderr', 'stderr_noise', 'stop_on_error', 'dry_run', 'plan', 'timeout', '_active_operation', '_operation_key', '_dormant_sudo', 'progress', 'cooldown', 'cooldown_policy', 'windows_creation_flags', 'windows_processes_to_cleanup', 'cli_errors', '_last_run', 'run_cache', '_NAME_VERSION_REGEXP')¶

Canonical declaration order of the attributes a manager class may override.

The documented convention every manager module follows: identity first, then the escalation policy, the version requirement, the CLI plumbing, the version probe, and the rarely-overridden toggles. Manager-specific constants (the _*_REGEXP parsers) are not governed and conventionally sit between the attributes and the operations. Consumed by test_content_order, which checks each manager’s relative declaration order against this sequence.

tests.test_managers.collect_props_ref()[source]¶

Build the canonical member-order reference for manager classes.

Attributes follow CANONICAL_ATTRS; methods follow the base classes’ own declaration order, CLIExecutor’s (binary discovery, version probe, execution engine) before PackageManager’s (helpers, availability, then the operations). The curated attribute list is cross-checked against the base classes so a new base attribute cannot silently escape governance.

tests.test_managers.test_operation_order()[source]¶

Operation IDs follow the order of the base manager class and of the CLI.

The subcommands span two section modules: the read-only queries in cli_explore, the state changers and diagnostics in cli_maintenance. Walked in that order, their definitions must follow the enum order.

tests.test_managers.test_content_order(manager_class)[source]¶

Lint each manager class to check its members follow the canonical order.

Attributes must follow CANONICAL_ATTRS and methods the base classes’ own declaration order (see collect_props_ref()); ungoverned names (manager-specific parsing constants and helpers) may sit anywhere.

tests.test_managers.test_anchored_regexes_scanning_whole_output_are_multiline()[source]¶

A line-anchored regex walked over a whole output must set re.MULTILINE.

Without the flag ^ binds to the start of the string, so findall and finditer return at most one match and every result after the first is dropped: silently, since a short listing is indistinguishable from a real one. The managers feeding a regex to parse_regex_lines() are not concerned, that helper splitting the output before matching, which is why the invariant is keyed on the call site rather than on the pattern.

flatpak shipped exactly this bug: its search reported only the first package because the sample in its docstring carries a single result line.

tests.test_managers.test_argv_literals_carry_no_shell_quoting()[source]¶

No argv literal may wrap itself in the quotes a shell would have eaten.

Managers build an argument list, never a shell line, so a literal like '"%n %v %o %c"' reaches the tool with its quotes intact and is read as part of the value. ports shipped exactly that for years: pkg echoed the quotes back around every record, so each package id began with a " and every description ended with one, and nothing failed loudly enough to notice. The docstring above it showed the shell form, which is correct for a human to type and wrong to paste into an argv.

The check is cheap because the population is small and static: every string constant handed to run_cli, build_cli or run across the package.

tests.test_managers.test_reads_inside_mutating_methods_survive_plan_mode()[source]¶

A read a mutating method needs must be exempted from plan capture.

mpm --plan decides what to record from the operation in flight, not from the command: any CLI call made while install, remove or upgrade is stamped gets written to the plan recorder and hands its caller an empty string. A method that queries before it acts therefore reads back nothing and concludes the package does not exist. ports did exactly that, failing every mpm --plan install with Could not resolve port origin, and sdkman reported every installed candidate as missing.

Two exemptions are accepted, matching the two shapes in the codebase: the helper passes force_exec=True (which lifts plan for that one call), or the caller re-stamps the block with acting_as naming the read it performs. The mutating call itself must stay outside such a stamp, or plan mode would run the change it exists to only print; that half is not checkable here and is left to review.

The check is deliberately narrow. It knows two ways a method triggers a read, the installed/outdated properties and a _resolve* helper, so a read reached by any other route passes unnoticed. It covers the population that has produced the bug twice, not every way of writing it.

tests.test_managers.test_operation_vocabularies_agree()[source]¶

The operation, capability and schema maps name the same methods.

Those are the method-to-operation map, the capability map and the definition schema. They also agree on the operations.

OPERATION_KEYS_BY_METHOD decides which operations entry a command takes its extra_args from. A method it misses builds commands that no entry reaches, and a name that differs from OPERATION_FACTORIES makes an override and a definition disagree on what the operation is called.

tests.test_managers.test_extra_args_call_sites_are_explicit()[source]¶

Each CLI call says whether it takes the user’s extra_args.

This applies to each call that may not be the command of its operation.

build_cli adds the extra_args of the operation in flight to every command an operation method builds, the calls of the helpers it reaches included. A helper command (brew tap before an install, a per-package info lookup) must not get them, so an explicit auto_extra_args keyword is required:

  • on each call in a method that is not an operation method;

  • on each call of an operation method that holds more than one.

A direct run() call skips build_cli: the operation method holding one must then splice active_extra_args() into its command itself. A call forwarding **kwargs passes the caller’s choice on, and the build_cli and run_cli overrides are covered by test_build_cli_adds_extra_args() instead.

tests.test_managers.test_build_cli_adds_extra_args(manager, monkeypatch)[source]¶

The build_cli of every manager adds the extra_args of the operation.

It adds those of the operation in flight, and leaves them out on request.

The shell-plugin managers override build_cli to wrap their command in a bash -c or fish -c string, without calling the base one: they splice the arguments in through active_extra_args(), so the sentinel sits inside that string.

tests.test_managers.test_operation_methods_stamp_their_own_entry(monkeypatch)[source]¶

A command gets the extra_args of the method that builds it.

Three shapes would fool a stamp keyed on the routed operation: a query that runs lazily, after its property returned; a query nested in another, like an outdated that reads installed; and the one-by-one fallback of a full upgrade, whose commands are upgrade_one commands.

tests.test_managers.test_version_probe_takes_no_extra_args(monkeypatch)[source]¶

The version probe never gets the user’s extra_args.

version is a cached property, so its probe runs wherever the manager first reads it, which can be inside an operation method.

tests.test_managers.declared_keywords(manager)[source]¶

Keywords the manager’s own class body sets, ignoring anything inherited.

A subclass reuses its parent’s implementation, which is not a second claim on the parent’s names: apt-mint inherits debian from apt, and every AUR helper inherits arch from pacman. Generation reads the inherited value, so a label still collects its members’ terms through a set union, but ownership is only what a class declares for itself.

Return type:

tuple[str, ...]

tests.test_managers.test_manager_keywords_have_one_owner()[source]¶

No two managers declare the same keyword alias.

A keyword names exactly one manager, so a term spanning several of them (an ecosystem name like zsh, answering for five plugin managers) belongs in the globally curated KEYWORDS_EXTRAS instead, which owes nothing to a single class. Without this, two managers could disagree about who a name refers to and both would ship it.

tests.test_managers.test_manager_keywords_are_not_manager_ids()[source]¶

A keyword never restates a manager ID.

Every ID already reaches the PyPI keywords straight from the pool, so repeating one is redundant. Repeating another manager’s ID is worse, since it would file that manager’s own name under this class.

tests.test_managers.test_manager_keywords_are_normalized()[source]¶

Keywords are stripped and lowercase.

They are merged into one case-insensitively sorted set, so a stray capital or a trailing space would produce a near-duplicate entry that the uniqueness check above cannot see.

tests.test_managers.test_parsed_json_is_never_subscripted()[source]¶

No parser indexes a top-level key its tool is free to omit.

A CLI with nothing to report often answers a different shape rather than an empty one. fwupdmgr --json replaces its whole payload with an Error object and exits 2, so data["Devices"] aborted every query reaching fwupd on any host with no updatable device: a VM, a container, plenty of real machines. Two such crashes came out of that one parser within a month (#2073 was the first), each found by a user rather than by CI.

They surface only on the empty result, which is the case nobody has the hardware to stage, so the guard is structural rather than another fixture: read a parsed payload with .get() and a default.