Skip to content

Commit

Permalink
add basic tests for returncode-attribute
Browse files Browse the repository at this point in the history
This commit adds some basic tests to verify
that the `returncode` attribute of the
`iterable_subprocess` generator is properly
set.
  • Loading branch information
christian-monch committed Dec 11, 2023
1 parent db0faa9 commit 89c966c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions datalad_next/iterable_subprocess/test_iterable_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,26 @@ def yield_input():

with iterable_subprocess(['funzip'], yield_input()) as output:
assert b''.join(output) == contents


def test_error_returncode_available_from_generator():
with pytest.raises(IterableSubprocessError):
with iterable_subprocess(['ls', 'does-not-exist'], ()) as ls:
tuple(ls)
assert ls.returncode != 0


def test_error_returncode_available_from_generator_with_exception():
with pytest.raises(StopIteration):
with iterable_subprocess(['ls', 'does-not-exist'], ()) as ls:
while True:
next(ls)
assert ls.returncode != 0


def test_success_returncode_available_from_generator_with_exception():
with pytest.raises(StopIteration):
with iterable_subprocess(['echo', 'a'], ()) as echo:
while True:
next(echo)
assert echo.returncode == 0

0 comments on commit 89c966c

Please sign in to comment.