tests.test_managers module¶
- 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_messageis only meaningful on an unmaintained manager.
- tests.test_managers.test_maintenance_note(manager)[source]¶
A
maintenance_noteis MyST markdown whose URLs arehttp(s)links.It is mutually exclusive with the
unmaintainedflag: a confirmed-dead manager documents itself with anunmaintained_messageinstead 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
Operationsvocabulary 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_operationsnames exactly thesudo=Trueoperations.Those are the operations whose methods carry a
sudo=Truemarker.prime_sudoreads 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 outsideMETHOD_OPERATIONSbelongs 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_user_install_dir_hooks_come_in_pairs(manager)[source]¶
A manager that finds a user directory also lists the packages in it.
refiltered_outdatedreads both hooks ofuser_install_dir: one without the other raisesNotImplementedErroron 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.
- tests.test_managers.MARKDOWN_LINK_URL = re.compile('\\]\\((https?://(?:[^()\\s]|\\([^()\\s]*\\))+)\\)')¶
The address of a markdown link, balanced parentheses included.
- tests.test_managers.test_docstring_repeats_no_card_link(manager)[source]¶
Check a docstring states no link its card already carries.
The manager’s page opens on its card, which links every
*_urlattribute, the documentation entry point among them. ADocumentation: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_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_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_regexesparses the documented--versionoutput.Regression guard for the case where
re.VERBOSEsilently swallowed literal spaces in patterns likeguix \(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
eopkglisting, header and===separator included.zram-generator-defaultsoverflows 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.0and5.0.0.
- tests.test_managers.test_eopkg_installed_reports_the_bare_version(stub_run_cli)[source]¶
installedreports theVersioncolumn alone, release excluded.Every snapshot carries this string, so the release stays out of it. Only
outdatedpairs 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]¶
outdatedpairs the installed listing with the candidateinforeports.list-upgrades --install-infodescribes each package as installed, so the upgrade target appears nowhere in it. The target comes from a second call,infotaking every name at once. Both sides carry the release, or theaalibrow below (a release-only rebuild) would read1.4.0_5on 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 infooutput captured verbatim.Both blocks come off a Solus
4.9host. The second is the one that matters: an installed package prints anInstalled package:section whoseName :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 searchemits the index’s raw summary, character references included.list-availableresolves the same text, so the two disagree on the very same package: onlysearchreaches a user through mpm, and it used to showImageMagick® suitewhere 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 --quietis one:--searchdrops to a bare* category/nameline without theLatest version available:andDescription:fields, and--update --columnsdrops 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_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
_*_REGEXPparsers) are not governed and conventionally sit between the attributes and the operations. Consumed bytest_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) beforePackageManager’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 incli_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_ATTRSand methods the base classes’ own declaration order (seecollect_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, sofindallandfinditerreturn 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 toparse_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.flatpakshipped 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.portsshipped exactly that for years:pkgechoed 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_cliorrunacross 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 --plandecides what to record from the operation in flight, not from the command: any CLI call made whileinstall,removeorupgradeis 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.portsdid exactly that, failing everympm --plan installwithCould not resolve port origin, andsdkmanreported 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 withacting_asnaming 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/outdatedproperties 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_METHODdecides whichoperationsentry a command takes itsextra_argsfrom. A method it misses builds commands that no entry reaches, and a name that differs fromOPERATION_FACTORIESmakes 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_cliadds theextra_argsof the operation in flight to every command an operation method builds, the calls of the helpers it reaches included. A helper command (brew tapbefore an install, a per-packageinfolookup) must not get them, so an explicitauto_extra_argskeyword 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 skipsbuild_cli: the operation method holding one must then spliceactive_extra_args()into its command itself. A call forwarding**kwargspasses the caller’s choice on, and thebuild_cliandrun_clioverrides are covered bytest_build_cli_adds_extra_args()instead.
- tests.test_managers.test_build_cli_adds_extra_args(manager, monkeypatch)[source]¶
The
build_cliof every manager adds theextra_argsof the operation.It adds those of the operation in flight, and leaves them out on request.
The shell-plugin managers override
build_clito wrap their command in abash -corfish -cstring, without calling the base one: they splice the arguments in throughactive_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_argsof 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
outdatedthat readsinstalled; and the one-by-one fallback of a full upgrade, whose commands areupgrade_onecommands.
- tests.test_managers.test_version_probe_takes_no_extra_args(monkeypatch)[source]¶
The version probe never gets the user’s
extra_args.versionis 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-mintinheritsdebianfromapt, and every AUR helper inheritsarchfrompacman. 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.
- 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 curatedKEYWORDS_EXTRASinstead, 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 --jsonreplaces its whole payload with anErrorobject and exits2, sodata["Devices"]aborted every query reachingfwupdon 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.