Skip to content

Commit

Permalink
psh: improve check psh
Browse files Browse the repository at this point in the history
Improve check for 'psh' when logs from other systems might appear

JIRA CI-316
  • Loading branch information
mateusz-bloch committed Aug 11, 2023
1 parent 0cb61c4 commit 010cdff
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
2 changes: 0 additions & 2 deletions psh/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ The python module `psh` makes writing harness tests easier. It provides the foll

* `assert_prompt_after_cmd(pexpect_proc, cmd, result='success', msg=None)` - Sends a command and asserts only `EOL` and next prompt. This method can be useful, when expecting command's output is not needed. Sent command isn't also asserted, so this function can be used for sending some unprintable characters. If it does not fail, the output caught before prompt will be returned. If the `msg` argument is not passed, the default error message will be used. The function also checks the exit code of a passed command in the same way as `assert_cmd()`.

* `assert_only_prompt(pexpect_proc)` - Asserts psh prompt with the appropriate esc sequence.

* `assert_prompt(pexpect_proc, msg='', timeout=-1, catch_timeout=True)` - Asserts psh prompt by searching only for `'(psh)% '` in buffer (without checking an escape sequence). There is also a possibility to pass a message to print if the assertion fails and set timeout arguments.

* `assert_prompt_fail(pexpect_proc, msg='', timeout=-1)` - Asserts that there is no psh prompt in the read buffer.
Expand Down
11 changes: 2 additions & 9 deletions psh/tools/psh.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ def assert_prompt_after_cmd(pexpect_proc, cmd, result='success', msg=None):
return output


def assert_only_prompt(pexpect_proc):
''' Expect an erase in display ascii escape sequence and a prompt sign '''
prompt = '\x1b[0J' + '(psh)% '
got = pexpect_proc.read(len(prompt))
assert got == prompt, f'Expected:\n{prompt}\nGot:\n{got}'


def assert_prompt(pexpect_proc, msg='', timeout=-1, catch_timeout=True):
patterns = ['(psh)% ']
if catch_timeout:
Expand Down Expand Up @@ -133,7 +126,7 @@ def get_exit_code(pexpect_proc):
assert pexpect_proc.expect([rf'(\d+?){EOL}', pexpect.TIMEOUT, pexpect.EOF]) == 0, msg

exit_code = int(pexpect_proc.match.group(1))
assert_only_prompt(pexpect_proc)
assert_prompt(pexpect_proc)

return exit_code

Expand Down Expand Up @@ -260,7 +253,7 @@ def init(pexpect_proc):
exec_cmd = _get_exec_cmd('psh')
pexpect_proc.sendline(exec_cmd)
pexpect_proc.expect(rf'{exec_cmd}(\r+)\n')
assert_only_prompt(pexpect_proc)
assert_prompt(pexpect_proc)


def deinit(pexpect_proc):
Expand Down

0 comments on commit 010cdff

Please sign in to comment.