Skip to content

Commit

Permalink
Make zxpy raise on error
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Sep 28, 2021
1 parent 0c067d3 commit 975e9b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/zxpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ def test_prints(capsys: pytest.CaptureFixture[str]) -> None:
def test_argv() -> None:
test_file = "./tests/test_files/argv.py"
subprocess.run(["zxpy", test_file])


def test_raise() -> None:
with pytest.raises(ChildProcessError) as exc:
zx.run_shell("exit 1")

assert exc.value.args == (1,)
9 changes: 8 additions & 1 deletion zx.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ def cli() -> None:
def create_shell_process(command: str) -> IO[bytes]:
"""Creates a shell process, returning its stdout to read data from."""
process = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
)
process.wait()
if process.returncode != 0:
raise ChildProcessError(process.returncode)

assert process.stdout is not None
return process.stdout

Expand Down

0 comments on commit 975e9b0

Please sign in to comment.