xonsh/tests/test_jobs.py
Peter Ye 86e4f004e3
Fix job control for callable aliases (#4901)
* Make job control task queue thread-local

This allows callable aliases to maintain a separate task queue from the
main thread.

* Make job control dictionary thread-local

Use XSH.all_jobs for the main thread and a separate dictionary for other
threads. This allows callable aliases to keep track of their jobs
separate from the main thread.

* Implement use_main_jobs() context manager

This allows threaded commands like jobs, disown, and bg to handle the
main thread's job control

* Run commands in the same process group if in a thread

* Fix tests that use jobs and tasks

* Add tests for subprocess call inside alias

* Add news

* Remove type declarations for _jobs_thread_local

Fixes the mypy error: "Type cannot be declared in assignment to non-self attribute"

Co-authored-by: Noorhteen Raja NJ <jnoortheen@gmail.com>
2022-08-03 11:37:26 +05:30

36 lines
859 B
Python

import pytest
from xonsh import jobs
@pytest.mark.parametrize(
"args, prefix, exp",
[
(
"disown",
"-",
{"-h", "--help", "-c", "--continue"},
),
(
"disown",
"",
{"1", "2"},
),
],
)
def test_disown_completion(
args, prefix, exp, xsh_with_aliases, monkeypatch, check_completer
):
job = {
"cmds": (["git-cola", "2>", "/dev/null"], "&"),
"pids": [37078],
"bg": True,
"pgrp": None,
"started": 1630158319.697764,
"status": "running",
}
all_jobs = {1: job, 2: job}
monkeypatch.setattr(jobs._jobs_thread_local, "jobs", all_jobs, raising=False)
monkeypatch.setattr(jobs._jobs_thread_local, "tasks", [2, 1], raising=False)
assert check_completer(args, prefix=prefix) == exp