Skip to content

Commit

Permalink
Handle None values for .stdout and .stderr on ``ProcessRe…
Browse files Browse the repository at this point in the history
…sult.__str__()``

Fixes saltstack#8

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
  • Loading branch information
s0undt3ch committed Feb 17, 2022
1 parent 0dc5398 commit 1860ff0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/8.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle ``None`` values for ``.stdout`` and ``.stderr`` on ``ProcessResult.__str__()``
6 changes: 3 additions & 3 deletions src/pytestshellutils/downgraded/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def __str__(self) -> str:
message += '\n Command Line: {0}'.format(self.cmdline)
if self.returncode is not None:
message += '\n Returncode: {0}'.format(self.returncode)
if self.stdout.strip() or self.stderr.strip():
if self.stdout and self.stdout.strip() or self.stderr and self.stderr.strip():
message += '\n Process Output:'
if self.stdout.strip():
if self.stdout and self.stdout.strip():
message += '\n >>>>> STDOUT >>>>>\n{0}\n <<<<< STDOUT <<<<<'.format(
self.stdout
)
if self.stderr.strip():
if self.stderr and self.stderr.strip():
message += '\n >>>>> STDERR >>>>>\n{0}\n <<<<< STDERR <<<<<'.format(
self.stderr
)
Expand Down
6 changes: 3 additions & 3 deletions src/pytestshellutils/utils/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def __str__(self) -> str:
message += f"\n Command Line: {self.cmdline}"
if self.returncode is not None:
message += f"\n Returncode: {self.returncode}"
if self.stdout.strip() or self.stderr.strip():
if (self.stdout and self.stdout.strip()) or (self.stderr and self.stderr.strip()):
message += "\n Process Output:"
if self.stdout.strip():
if self.stdout and self.stdout.strip():
message += f"\n >>>>> STDOUT >>>>>\n{self.stdout}\n <<<<< STDOUT <<<<<"
if self.stderr.strip():
if self.stderr and self.stderr.strip():
message += f"\n >>>>> STDERR >>>>>\n{self.stderr}\n <<<<< STDERR <<<<<"
if self.data:
message += "\n Parsed JSON Data:\n"
Expand Down

0 comments on commit 1860ff0

Please sign in to comment.