Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep args the same as subprocess.run #40

Merged
merged 2 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/subprocess_tee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ def run(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess:

loop = asyncio.get_event_loop()
result = loop.run_until_complete(_stream_subprocess(cmd, **kwargs))
# we restore original args to mimic subproces.run()
result.args = args

if check and result.returncode != 0:
raise subprocess.CalledProcessError(
result.returncode, cmd, output=result.stdout, stderr=result.stderr
result.returncode, args, output=result.stdout, stderr=result.stderr
)
return result
17 changes: 17 additions & 0 deletions src/subprocess_tee/test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,20 @@ def test_run_with_check_pass() -> None:
assert ours.args == original.args
assert ours.stdout == original.stdout
assert ours.stderr == original.stderr


def test_run_compat() -> None:
"""Assure compatiblity with subprocess.run()"""
cmd = ["seq", "10"]
ours = run(cmd)
original = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
check=False,
)
assert ours.returncode == original.returncode
assert ours.stdout == original.stdout
assert ours.stderr == original.stderr
assert ours.args == original.args
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ passenv =
TERM
setenv =
PIP_DISABLE_VERSION_CHECK=1
PYTEST_REQPASS=14
PYTEST_REQPASS=15
PYTHONDONTWRITEBYTECODE=1
PYTHONUNBUFFERED=1
commands =
Expand Down