tests.test_jobs module¶
Tests for the –jobs option and the run_jobs and run_lanes fan-out primitives.
- tests.test_jobs.test_default_value(invoke)[source]¶
Default reserves one core, except on hosts with fewer than three CPUs.
- tests.test_jobs.test_keyword_resolution(invoke, keyword, expected)[source]¶
‘auto’ resolves to the reserved-core default, ‘max’ to all logical CPUs.
On a host with at least two logical CPUs the resolution is silent; on a single-CPU host the keyword collapses to a single (sequential) job with a warning, so the assertion adapts to the host running the suite.
- tests.test_jobs.test_parallel_keyword_collapses_to_sequential_warns(invoke, keyword, cpu_count, default_jobs, cpu_phrase)[source]¶
‘auto’/’max’ warn when too few logical CPUs force a single (sequential) job.
- tests.test_jobs.test_explicit_single_job_is_silent(invoke)[source]¶
An explicit ‘–jobs 1’ is a deliberate sequential choice: no warning.
- tests.test_jobs.test_default_collapse_to_sequential_is_quiet(invoke)[source]¶
The bare default (‘auto’) collapsing to a single job does not warn.
The user never asked for parallelism: warning on the option’s own default would fire on every bare invocation on a 1-CPU host, polluting captured runner streams and the CLI output rendered in Sphinx docs.
- tests.test_jobs.test_default_collapse_to_sequential_logged_at_info(invoke)[source]¶
The default’s collapse to a single job stays discoverable at info level.
This is the silent trap on a single-CPU host: no flag is passed, yet execution runs sequentially. The trace lives at info level, next to the resolved-jobs line, instead of a default-verbosity warning.
- tests.test_jobs.test_resolved_job_count_logged_at_info(invoke)[source]¶
The resolved job count and os.cpu_count() are logged at info level.
- tests.test_jobs.test_run_jobs_preserves_order(jobs)[source]¶
Results come back in submission order, sequential or parallel.
- tests.test_jobs.test_run_jobs_sequential_is_lazy()[source]¶
With one worker, items run lazily so a caller can stop early.
- tests.test_jobs.test_run_jobs_preserves_order_past_its_window(jobs)[source]¶
Order holds when the stream is longer than the in-flight window.
- tests.test_jobs.test_run_jobs_handles_empty_and_single_streams(jobs)[source]¶
The peek that sizes the run does not lose the items it looked at.
- tests.test_jobs.test_run_jobs_parallel_reads_no_further_than_its_window()[source]¶
The parallel path pulls a bounded window instead of draining the stream.
- tests.test_jobs.test_run_jobs_parallel_stops_scheduling_on_early_exit()[source]¶
Breaking out of a parallel run leaves the rest of the stream unread.
- tests.test_jobs.test_run_jobs_reads_jobs_from_context(invoke)[source]¶
Without an explicit count, run_jobs reads the resolved –jobs value.
- tests.test_jobs.test_run_jobs_without_context_runs_sequential()[source]¶
Outside any Click context and with no count, run_jobs falls back to 1.
- tests.test_jobs.test_run_jobs_interrupt_aborts_without_blocking()[source]¶
A KeyboardInterrupt returns at once, without waiting on in-flight tasks.
Results yield in submission order, so the interrupting item (index 0) is pulled first: the abort fires while a second, still-running item is parked on an event that stays unset for the run. A plain
with-block teardown wouldshutdown(wait=True)and hang on that parked task; the run drops queued work and returns at once.
- tests.test_jobs.test_resolve_jobs_without_context_is_sequential()[source]¶
No context means nothing to read a job count from: stay sequential.
- tests.test_jobs.test_resolve_jobs_single_item_is_sequential()[source]¶
A single item has nothing to parallelize.
- tests.test_jobs.test_resolve_jobs_reads_context(jobs, count, expected)[source]¶
The resolved –jobs value drives the count, capped at the item count.
- tests.test_jobs.test_resolve_jobs_serial_at_debug()[source]¶
serial_at_debug collapses to sequential only at DEBUG verbosity.
- tests.test_jobs.test_run_lanes_preserves_order(jobs)[source]¶
Results come back in lane-submission order, items within a lane in order.
- tests.test_jobs.test_run_lanes_preserves_order_past_its_window(jobs)[source]¶
Lane order holds when there are more lanes than the in-flight window.
- tests.test_jobs.test_run_lanes_materializes_lanes_lazily()[source]¶
A lane becomes a list only when it is about to be scheduled.
- tests.test_jobs.test_run_lanes_is_run_jobs_with_singleton_lanes()[source]¶
run_jobs is the degenerate case of run_lanes: one item per lane.
- tests.test_jobs.test_run_lanes_serializes_within_a_lane()[source]¶
Within a lane, items run one at a time even when lanes run in parallel.
- tests.test_jobs.test_run_lanes_runs_lanes_concurrently()[source]¶
Distinct lanes overlap: a barrier only releases if all lanes run at once.
- tests.test_jobs.test_run_lanes_sequential_is_lazy()[source]¶
With one worker, items run lazily so a caller can stop early.
- tests.test_jobs.test_run_lanes_reads_jobs_from_context(invoke)[source]¶
Without an explicit count, run_lanes reads the resolved –jobs value.
- tests.test_jobs.test_run_lanes_without_context_runs_sequential()[source]¶
Outside any Click context and with no count, run_lanes falls back to 1.
- tests.test_jobs.test_run_lanes_empty_yields_nothing()[source]¶
No lanes, or only empty lanes, yields nothing and raises nothing.
- tests.test_jobs.test_lone_item_or_lane_runs_in_the_calling_thread(run)[source]¶
With nothing to overlap, the work runs in the calling thread, whatever the worker count.
- tests.test_jobs.test_run_lanes_interrupt_aborts_without_blocking()[source]¶
A KeyboardInterrupt returns at once, without waiting on in-flight lanes.
Mirror of
test_run_jobs_interrupt_aborts_without_blocking(): see it for the rationale.
- tests.test_jobs.test_run_lanes_interrupt_stops_each_lane_after_its_current_item()[source]¶
An interrupt lets each running lane finish its current item, then stop.
- tests.test_jobs.test_interrupt_tripped_as_the_wait_began_is_handled_promptly(run)[source]¶
A Ctrl+C the interpreter noted as the main thread blocked on a task is handled within the poll period, not when the task ends.
interrupt_main()leaves the interrupt pending without waking the main thread: the state aSIGINTleaves when it lands after the interpreter last checked for one and before the thread blocked in the C library. An unbounded wait on the task would run the handler only when the task returns.
- tests.test_jobs.test_wait_result_raises_the_interrupt_a_lock_error_replaced(monkeypatch, context, expected)[source]¶
A
RuntimeErrorthe wait raises in place of a Ctrl+C becomes the Ctrl+C again.A free-threaded CPython can raise the interrupt between the wait and the lock it takes back, then fail to release it, as python/cpython#118433 reports. Any other
RuntimeErrorof the wait stays as it is.
- tests.test_jobs.test_run_jobs_reports_a_task_timeout_error()[source]¶
A task raising
TimeoutErrorends the run on it, within the poll period.concurrent.futures.TimeoutErroris the builtinTimeoutErrorfrom Python 3.11 on, which a task raises itself when a socket times out: a wait reading the result with a timeout of its own could not tell the two apart.
- tests.test_jobs.test_invalid_value(invoke)[source]¶
Values that are neither an integer nor a known keyword are rejected.
- tests.test_jobs.test_jobs_shell_complete(incomplete, expected)[source]¶
–jobs completion suggests the auto/max keywords and never an integer.
- tests.test_jobs.test_clamp_to_one(invoke, value, warning)[source]¶
0 disables parallelism and negatives clamp: both run 1 job with a warning.
- tests.test_jobs.test_exceeds_cpu_count(invoke)[source]¶
A count above the core count is honored, with an I/O-bound caveat.
- tests.test_jobs.test_no_warning_within_bounds(invoke)[source]¶
No warning when the value is within the valid range.
- tests.test_jobs.test_default_jobs(cpu_count, expected)[source]¶
The default reserves one logical CPU, from three CPUs up.
- tests.test_jobs.test_default_jobs_of_this_host()[source]¶
The published default follows the rule for the CPUs of this host.