tests.test_dispatch module

Unit tests for the concurrent operation dispatch helpers.

These exercise meta_package_manager.dispatch.collect_from_managers(), meta_package_manager.dispatch.collect_per_package() and the meta_package_manager.dispatch.OperationTrail they share, in isolation with lightweight stand-ins for the click context and managers, so they need no real package managers and stay hermetic. The context is passed explicitly as ctx= (the helpers otherwise default to click_extra.get_current_context()).

tests.test_dispatch.capable_term(monkeypatch)[source]

Pin TERM to a terminal the progress indicator can draw on.

Every test below fakes an interactive terminal with TTYStringIO, whose isatty() says yes while TERM keeps whatever the environment holds. No real terminal pairs those: a developer shell carries a capable TERM and the tests pass, an RPM or Debian build sandbox carries TERM=unknown and click-extra silences the aggregate indicator, taking the ✓/✘ trail with it. Five tests then fail for a reason no user meets, since mpm itself prints the trail under unknown and dumb alike.

Pinned for the module rather than per test, so a test added later inherits a terminal instead of the build host’s.

class tests.test_dispatch.FakeContext(jobs, verbosity='INFO')[source]

Bases: object

Minimal stand-in exposing only the meta keys the helper reads.

tests.test_dispatch.ALL_OPERATIONS = frozenset({'cleanup', 'install', 'remove', 'sync', 'upgrade', 'upgrade_all'})

The operations an internal escalator may run its own sudo in, by default.

class tests.test_dispatch.StubManager(manager_id, progress=False, internal_sudo=False, resets_sudo_timestamp=False, internal_sudo_operations=frozenset({'cleanup', 'install', 'remove', 'sync', 'upgrade', 'upgrade_all'}))[source]

Bases: object

Minimal stand-in exposing what dispatch reads off a manager.

internal_sudo and resets_sudo_timestamp default off, and internal_sudo_operations to every mutating operation, as they do on a real manager: dispatch reads them on every lane to decide which are held back to the sequential tail, so a stub without them would be a manager no scheduler could place. _active_operation defaults to None for the same reason, that being the class-level default of CLIExecutor._active_operation, and subject mirrors the property the trail reads to name each line.

run_cache = None
property subject: str
class tests.test_dispatch.TTYStringIO(initial_value='', newline='\n')[source]

Bases: StringIO

An in-memory text buffer that claims to be an interactive terminal.

isatty()[source]

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

Return type:

bool

tests.test_dispatch.test_runs_sequentially_in_main_thread(jobs, verbosity, manager_count)[source]
tests.test_dispatch.test_runs_concurrently_off_the_main_thread()[source]
tests.test_dispatch.test_preserves_input_order_despite_completion_order()[source]

Results follow the manager order, even when later managers finish first.

tests.test_dispatch.test_per_manager_spinners_follow_the_job_count(jobs, count, progress)[source]
tests.test_dispatch.test_empty_manager_list_returns_empty()[source]
tests.test_dispatch.test_finisher(ok, total, skipped, outcome, summary)[source]

The count leaves the skips out, and a batch of skips alone closes on ⊘.

tests.test_dispatch.test_no_finisher_line_off_terminal(capsys)[source]

Off a terminal the aggregate progress bar never draws, so no finisher leaks.

The indicator emits its kept line unconditionally, so the gate must keep it out of pipes, captured output and serialized runs.

tests.test_dispatch.test_finisher_line_when_progress_bar_shown(monkeypatch)[source]

A slow batch on a terminal shows the running count, a ✓ trail and a finisher.

tests.test_dispatch.test_failure_trail_marks_errored_managers(monkeypatch)[source]

A manager whose result carries errors gets a ✘ trail line; others get ✓.

tests.test_dispatch.test_trail_label_shapes(monkeypatch, item, detail, expected)[source]

Subject, then the package for a package-keyed line, then a detail.

tests.test_dispatch.test_trail_detail_composes_on_the_subject(monkeypatch)[source]

A detail renders as a parenthesized suffix, never in the subject’s place.

cleanup passes its categories and upgrade --all the cooldown that held a manager. Both used to replace the line’s whole text, so those lines named the bare manager while every other trail line named manager.operation.

tests.test_dispatch.test_trail_includes_managers_that_finish_before_the_indicator_shows(monkeypatch)[source]

Managers that complete within the show delay still get a trail line.

Regression: the per-manager echo was gated on the live shown state, so a manager that finished before the indicator first drew was dropped from the trail (a 6-manager batch where the quick ones beat the 1s delay showed only the 3 slow ones, above a “Checked 6 managers” finisher). Outcomes are now buffered and flushed once the indicator appears, so the ledger stays complete.

tests.test_dispatch.test_per_package_runs_sequentially_in_main_thread(jobs, verbosity, manager_count)[source]
tests.test_dispatch.test_per_package_runs_concurrently_off_the_main_thread()[source]
tests.test_dispatch.test_per_package_tasks_of_one_manager_share_a_thread()[source]

A manager’s own tasks run serially on one worker, never overlapping.

The core safety invariant: a package manager cannot run two of its own invocations at once, so each lane’s tasks stay on a single thread. Repeating the same manager instance across pairs groups its tasks into one lane.

tests.test_dispatch.test_per_package_empty_is_a_noop()[source]
tests.test_dispatch.test_per_package_finisher_when_progress_bar_shown(monkeypatch)[source]

A slow concurrent batch shows the running count, a ✓ trail and a finisher.

tests.test_dispatch.test_per_package_failure_trail_marks_failed_tasks(monkeypatch)[source]

A failed task gets a ✘ line; the finisher reports the success count.

tests.test_dispatch.test_per_package_finisher_survives_off_terminal(capsys)[source]

Off a terminal the finisher still prints: the record must reach a log.

The animated aggregate indicator cannot draw on a pipe, so the plain lines take over. That is the whole point of the split, and it is why a CI log or a redirected run keeps an account of what happened.

tests.test_dispatch.test_lock_family_members_share_one_lane_when_mutating()[source]

brew and cask (one family) run on a single worker; an outsider gets its own.

tests.test_dispatch.test_lock_family_not_serialized_for_reads()[source]

Reads take no backend lock, so family members keep separate lanes and threads.

tests.test_dispatch.test_lock_family_members_share_one_lane_in_collect_per_package()[source]

A family’s tasks serialize across its managers in the per-package fan-out too.

tests.test_dispatch.test_lock_family_lane_shares_a_run_cache()[source]

A multi-manager family lane injects one shared run_cache, cleared afterwards.

tests.test_dispatch.test_internal_escalator_runs_in_a_sequential_tail(monkeypatch, operation, escalates_in, warm, resets, held_back)[source]

A manager escalating internally runs once the concurrent batch is done.

Its hidden sudo prompt then lands on a terminal nothing else writes to.

The tail runs at jobs=1, which run_lanes executes inline, so the held-back manager is the one that ran on the calling thread. An operation in which the tool never escalates keeps every manager in the concurrent phase, on a pool worker. So does a warm credential cache, unless the tool drops it before its own sudo.

tests.test_dispatch.test_sequential_tail_reports_one_batch_wide_finisher(monkeypatch)[source]

Two phases, one finisher: the tail closes the batch with the whole tally.

A held-back manager then never reads as a second run of its own.

tests.test_dispatch.test_operation_trail_echoes_marks_and_finisher_on_tty(monkeypatch)[source]

On a TTY the ledger echoes a ✓/✘ line per mark, plus a finisher.

The finisher carries an elapsed time only under --time: upstream gates it on OperationTrail’s timer argument, which mpm leaves at its None default so the flag decides. It used to clock unconditionally.

tests.test_dispatch.test_operation_trail_silent_without_progress(capsys)[source]

Progress off is the one thing that silences the ledger.

The control for the two tests around it: they assert the lines survive a pipe, and this pins what still suppresses them. It guards the visible argument the trail is built with, which is not interchangeable with live: the latter only moves the aggregate indicator, and where that cannot draw each outcome line prints instead, so gating on it would silence nothing.

tests.test_dispatch.test_operation_trail_echoes_off_terminal(capsys)[source]

Off a terminal the sequential ledger prints rather than staying silent.

Its lines only ever append, so they survive a pipe where an animation redrawing in place could not. Progress off is what silences them, through visible, not the absence of a terminal.