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
TERMto a terminal the progress indicator can draw on.Every test below fakes an interactive terminal with
TTYStringIO, whoseisatty()says yes whileTERMkeeps whatever the environment holds. No real terminal pairs those: a developer shell carries a capableTERMand the tests pass, an RPM or Debian build sandbox carriesTERM=unknownand click-extra silences the aggregate indicator, taking the✓/✘trail with it. Five tests then fail for a reason no user meets, sincempmitself prints the trail underunknownanddumbalike.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:
objectMinimal stand-in exposing only the
metakeys 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
sudoin, 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:
objectMinimal stand-in exposing what
dispatchreads off a manager.internal_sudoandresets_sudo_timestampdefault off, andinternal_sudo_operationsto every mutating operation, as they do on a real manager:dispatchreads 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_operationdefaults toNonefor the same reason, that being the class-level default ofCLIExecutor._active_operation, andsubjectmirrors the property the trail reads to name each line.- run_cache = None¶
- class tests.test_dispatch.TTYStringIO(initial_value='', newline='\n')[source]¶
Bases:
StringIOAn in-memory text buffer that claims to be an interactive terminal.
- 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_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
detailrenders as a parenthesized suffix, never in the subject’s place.cleanuppasses its categories andupgrade --allthe 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 namedmanager.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
shownstate, 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]¶
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_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.
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.
A family’s tasks serialize across its managers in the per-package fan-out too.
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
sudoprompt then lands on a terminal nothing else writes to.The tail runs at
jobs=1, whichrun_lanesexecutes 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 ownsudo.
- 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 onOperationTrail’stimerargument, which mpm leaves at itsNonedefault 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
visibleargument the trail is built with, which is not interchangeable withlive: 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.