Skip to content

Commit

Permalink
Bugfix: set exit_code when using stream (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored Jul 22, 2020
1 parent 1805234 commit 374e874
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.2.3
- Bugfix: `exit_code` was not being set when using `stream=True`. This was fixed by calling `Popen.poll()`

## v0.2.2

- `exit_code` is now a property, `status_code` is still supported but will be deprecated
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pybuild:
rm -rf dist/*
python setup.py sdist bdist_wheel

upload:
twine check dist/*
twine upload dist/*
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='soldier',
version='0.2.2',
version='0.2.3',
author='Yash Mehrotra',
author_email='[email protected]',
packages=['soldier'],
Expand Down
2 changes: 2 additions & 0 deletions soldier/soldier.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ def _set_communication_params(self, wait=False):
sys.stdout.write(line)
output += line
self._output = output
self._err = self._process.stderr.read()
else:
self._output, self._err = self._process.communicate(self._output)

# This even comes as an output for stderr
if self._err and not self._suppress_std_err:
print(self._err)

self._process.poll()
self._exit_code = self._process.returncode

def _finish(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ def test_stream(self):

s = soldier.run('ls')
command_output = s.output.strip().split('\n')

assert stream_output == command_output

def test_stream_exit_code(self):
s = soldier.run('echo hello > /dev/null', stream=True)
assert s.exit_code == 0

0 comments on commit 374e874

Please sign in to comment.