diff options
Diffstat (limited to 'test/units')
-rw-r--r-- | test/units/ansible_test/_internal/__init__.py | 0 | ||||
-rw-r--r-- | test/units/ansible_test/_internal/test_util.py | 36 | ||||
-rw-r--r-- | test/units/ansible_test/conftest.py | 4 |
3 files changed, 38 insertions, 2 deletions
diff --git a/test/units/ansible_test/_internal/__init__.py b/test/units/ansible_test/_internal/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/units/ansible_test/_internal/__init__.py diff --git a/test/units/ansible_test/_internal/test_util.py b/test/units/ansible_test/_internal/test_util.py new file mode 100644 index 0000000000..97e2f05dd7 --- /dev/null +++ b/test/units/ansible_test/_internal/test_util.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +import pytest + + +def test_failed_non_interactive_captured_command() -> None: + """Verify failed non-interactive captured commands raise a `SubprocessError` with `stdout` and `stderr` set.""" + from ansible_test._internal.util import raw_command, SubprocessError + + with pytest.raises(SubprocessError, match='Command "ls /dev/null /does/not/exist" returned exit status [0-9]+.\n>>> Standard Error\n') as error: + raw_command(['ls', '/dev/null', '/does/not/exist'], True) + + assert '/dev/null' in error.value.stdout + assert '/does/not/exist' in error.value.stderr + + +def test_failed_non_interactive_command() -> None: + """Verify failed non-interactive non-captured commands raise a `SubprocessError` with `stdout` and `stderr` set to an empty string.""" + from ansible_test._internal.util import raw_command, SubprocessError + + with pytest.raises(SubprocessError, match='Command "ls /dev/null /does/not/exist" returned exit status [0-9]+.') as error: + raw_command(['ls', '/dev/null', '/does/not/exist'], False) + + assert error.value.stdout == '' + assert error.value.stderr == '' + + +def test_failed_interactive_command() -> None: + """Verify failed interactive commands raise a `SubprocessError` with `stdout` and `stderr` set to `None`.""" + from ansible_test._internal.util import raw_command, SubprocessError + + with pytest.raises(SubprocessError, match='Command "ls /dev/null /does/not/exist" returned exit status [0-9]+.') as error: + raw_command(['ls', '/dev/null', '/does/not/exist'], False, interactive=True) + + assert error.value.stdout is None + assert error.value.stderr is None diff --git a/test/units/ansible_test/conftest.py b/test/units/ansible_test/conftest.py index 20e30aeb55..130c5c8742 100644 --- a/test/units/ansible_test/conftest.py +++ b/test/units/ansible_test/conftest.py @@ -7,7 +7,7 @@ import sys @pytest.fixture(autouse=True, scope='session') -def ansible_test(): - """Make ansible_test available on sys.path for unit testing ansible-test.""" +def inject_ansible_test(): + """Make ansible_test available on `sys.path` for unit testing ansible-test.""" test_lib = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'lib') sys.path.insert(0, test_lib) |