Skip to content

Commit

Permalink
bug fix for picking ProcessExecutionError with stdout/stderr buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
koreno committed Feb 7, 2023
1 parent 6dd012f commit 6224889
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plumbum/commands/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class ProcessExecutionError(EnvironmentError):
well as the command line used to create the process (``argv``)
"""

def __init__(self, argv, retcode, stdout, stderr, message=None, host=None):
def __init__(
self, argv, retcode, stdout=None, stderr=None, message=None, host=None
):

# we can't use 'super' here since EnvironmentError only keeps the first 2 args,
# which leads to failuring in loading this object from a pickle.dumps.
Expand Down Expand Up @@ -144,7 +146,7 @@ def __init__(self, argv, retcode, stdout, stderr, message=None, host=None):
self.all_output += ["\nStderr: | ", stderr]

def _format_lines(self, lines):
fd_names = ['stdout', 'stderr']
fd_names = ["stdout", "stderr"]
for idx, ts, stream_fd, line in lines:
source = fd_names[stream_fd - 1]
for _line in line.splitlines():
Expand Down Expand Up @@ -399,7 +401,7 @@ def iter_lines(
ret[t] = line
yield tuple(ret)
elif mode is BY_TYPE:
yield (stream_fd), line
yield (stream_fd), line

# this will take care of checking return code and timeouts
_check_process(proc, retcode, timeout, *buffers)
5 changes: 5 additions & 0 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,15 @@ def test_exceptions(self):

def test_exception_pickling(self):
import pickle

with pytest.raises(ProcessExecutionError) as exc_info:
local.cmd.ls("no-file")
assert pickle.loads(pickle.dumps(exc_info.value)).argv == exc_info.value.argv

with pytest.raises(ProcessExecutionError) as exc_info:
list(local.cmd.ls["no-file"].popen())
assert pickle.loads(pickle.dumps(exc_info.value)).argv == exc_info.value.argv

def test_tempdir(self):
with local.tempdir() as dir:
assert dir.is_dir()
Expand Down

0 comments on commit 6224889

Please sign in to comment.