Commit d4648f57 by Peter Weidenbach

refactoring

parent 5cfc68cd
......@@ -30,18 +30,18 @@ def execute_shell_command_get_return_code(shell_command, timeout=None):
:return: str, int
"""
output = ""
rc = 1
return_code = 1
pl = Popen(shell_command, shell=True, stdout=PIPE, stderr=STDOUT)
try:
output = pl.communicate(timeout=timeout)[0].decode('utf-8', errors='replace')
rc = pl.returncode
return_code = pl.returncode
except TimeoutExpired:
logging.warning("Execution timeout!")
pl.kill()
output = pl.communicate()[0].decode('utf-8', errors='replace')
output += "\n\nERROR: execution timed out!"
rc = 1
return output, rc
return_code = 1
return output, return_code
def execute_interactive_shell_command(shell_command, timeout=60, inputs={}):
......
......@@ -7,7 +7,7 @@ from common_helper_process import execute_shell_command, execute_shell_command_g
from common_helper_process.fail_safe_subprocess import _parse_inputs
class TestProcessHelper(unittest.TestCase):
class TestProcessHelperPublic(unittest.TestCase):
def test_execute_shell_command(self):
result = execute_shell_command("echo 'test 123'")
......@@ -35,11 +35,12 @@ class TestProcessHelper(unittest.TestCase):
self.assertEqual(rc, 1, 'return code not correct')
self.assertGreater(5, run_time, "command not aborted")
def test_parse_inputs(self):
test_dict = {'a': 'a_out', 'b': 'b_out'}
trigger, inputs = _parse_inputs(test_dict)
self.assertEqual(trigger, ['a', 'b'])
self.assertEqual(inputs, ['a_out', 'b_out'])
def test_interactive_shell_command_none_correct_input(self):
script_path = os.path.join(get_dir_of_file(__file__), 'data/interactive.sh')
output, ret_code = execute_interactive_shell_command(script_path, timeout=2)
assert 'give me some input' in output
assert '\n\nError: Execution timed out!' in output
assert ret_code > 0
def test_interactive_shell_command(self):
script_path = os.path.join(get_dir_of_file(__file__), 'data/interactive.sh')
......@@ -49,9 +50,11 @@ class TestProcessHelper(unittest.TestCase):
assert 'second=test_input_2' in output
assert ret_code == 0
def test_interactive_shell_command_none_correct_input(self):
script_path = os.path.join(get_dir_of_file(__file__), 'data/interactive.sh')
output, ret_code = execute_interactive_shell_command(script_path, timeout=2)
assert 'give me some input' in output
assert '\n\nError: Execution timed out!' in output
assert ret_code > 0
class TestProcessHelperInternal(unittest.TestCase):
def test_parse_inputs(self):
test_dict = {'a': 'a_out', 'b': 'b_out'}
trigger, inputs = _parse_inputs(test_dict)
self.assertEqual(trigger, ['a', 'b'])
self.assertEqual(inputs, ['a_out', 'b_out'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment