Skip to content

Commit

Permalink
run: ensure stdout and stderr are bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed May 18, 2024
1 parent 31a26ce commit e0f0cbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions automon/helpers/subprocessWrapper/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ def set_command(self, command: str) -> bool:
return False

@property
def stdout(self):
def stdout(self) -> bytes:
if type(self._stdout) is str:
return str(self._stdout).encode()

return self._stdout

@property
def stdout_lines(self):
return self.stdout.decode().splitlines()

@property
def stderr(self):
def stderr(self) -> bytes:
if type(self._stderr) is str:
return str(self._stderr).encode()

return self._stderr

@property
Expand Down
14 changes: 14 additions & 0 deletions automon/helpers/subprocessWrapper/tests/test_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import unittest

from automon.helpers.subprocessWrapper import Run


class TestRun(unittest.TestCase):
def test_text(self):
run = Run()
run.run('ls', text=True)
self.assertEqual(type(run.stdout), bytes)


if __name__ == '__main__':
unittest.main()

0 comments on commit e0f0cbb

Please sign in to comment.