left4me/components/l4d2-host-lib/tests/test_process.py

22 lines
553 B
Python

import subprocess
import pytest
from l4d2host.process import run_command
def test_callbacks_receive_lines() -> None:
out: list[str] = []
err: list[str] = []
run_command(
["python3", "-c", "import sys; print('ok'); print('warn', file=sys.stderr)"],
on_stdout=out.append,
on_stderr=err.append,
)
assert out == ["ok"]
assert err == ["warn"]
def test_nonzero_exit_raises() -> None:
with pytest.raises(subprocess.CalledProcessError):
run_command(["python3", "-c", "import sys; sys.exit(7)"])