Skip to content

Commit

Permalink
psh: tools: add timeout to assert_cmd
Browse files Browse the repository at this point in the history
JIRA: CI-326
  • Loading branch information
maska989 committed Oct 10, 2023
1 parent 00dcbbe commit 6535925
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions psh/tools/psh.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def _check_result(pexpect_proc, result):
'Please choose between susccess/fail/dont-check')))


def assert_cmd(pexpect_proc, cmd, *, expected='', result='success', msg='', is_regex=False):
''' Sends specified command and asserts that it's displayed correctly
with optional expected output and next prompt. Exit status is asserted depending on `result`'''
def assert_cmd(pexpect_proc, cmd, *, expected="", result="success", msg="", is_regex=False, timeout=30):
"""Sends specified command and asserts that it's displayed correctly
with optional expected output and next prompt. Exit status is asserted depending on `result`"""
pexpect_proc.sendline(cmd)
cmd = re.escape(cmd)
exp_regex = ''
exp_regex = ""
if is_regex:
exp_regex = expected
elif expected != '':
elif expected != "":
if not (isinstance(expected, tuple) or isinstance(expected, list)):
expected = tuple((expected,))
for line in expected:
Expand All @@ -67,9 +67,9 @@ def assert_cmd(pexpect_proc, cmd, *, expected='', result='success', msg='', is_r

exp_regex = cmd + EOL + exp_regex + PROMPT
exp_readable = _readable(exp_regex)
msg = f'Expected output regex was: \n---\n{exp_readable}\n---\n' + msg
msg = f"Expected output regex was: \n---\n{exp_readable}\n---\n" + msg

assert pexpect_proc.expect([exp_regex, pexpect.TIMEOUT, pexpect.EOF]) == 0, msg
assert pexpect_proc.expect([exp_regex, pexpect.TIMEOUT, pexpect.EOF], timeout=timeout) == 0, msg

_check_result(pexpect_proc, result)

Expand Down

0 comments on commit 6535925

Please sign in to comment.