Source code for ewoksmx.tests.shell_utils.test_execute_local

import logging

import pytest

from ewoksmx.shell_utils.execute_local import execute_bash_commands


[docs] def test_execute_bash_commands_success(caplog, capsys, tmp_path): commands = [ 'echo "Job start!"', 'echo "This is a test message for STDOUT"', '>&2 echo "This is a test message for STDERR"', "hostname", 'echo "Job finished!"', ] result = execute_bash_commands(commands, tmp_path) result.print() with caplog.at_level(logging.DEBUG): result.log() result.raise_on_error() assert "This is a test message for STDOUT" in (result.read_log() or "") assert "This is a test message for STDERR" in (result.read_log() or "") assert "Job start!" in (result.read_log() or "") assert "Job finished!" in (result.read_log() or "") captured = capsys.readouterr() assert "This is a test message for STDOUT" in captured.out assert "This is a test message for STDERR" in captured.out assert any( "This is a test message for STDOUT" in record.message for record in caplog.records ) assert any( "This is a test message for STDERR" in record.message for record in caplog.records )
[docs] def test_execute_bash_commands_failure(tmp_path): commands = [ 'echo "Job start!"', 'echo "This is a test message for STDOUT"', '>&2 echo "This is a test message for STDERR"', "ls /cause_error", 'echo "Job finished!"', ] result = execute_bash_commands(commands, tmp_path) with pytest.raises(RuntimeError): result.raise_on_error()