import inspect 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)"]) def test_run_command_avoids_runtime_unsafe_nested_annotations() -> None: source = inspect.getsource(run_command) assert "subprocess.Popen[str].stdout" not in source