test.expect(): Add support for log_act command line arg

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2023-01-17 11:53:01 +01:00
commit 2a7267a004

View file

@ -8,11 +8,13 @@ from ..misc import *
from ..Connection import Connection from ..Connection import Connection
from ..Connections import Connections from ..Connections import Connections
async def expect(conn, cmd=None, regex=None, subject=None, act_timeout=0.1, total_timeout=None): # export async def expect(conn, cmd=None, regex=None, subject=None, act_timeout=0.1, total_timeout=None, log_act=None): # export
# regex is a keyword-argument so that other arguments to support other # regex is a keyword-argument so that other arguments to support other
# checks can be added later # checks can be added later
if regex is None: if regex is None:
raise Exception("passed empty pattern to test.expect()") raise Exception("passed empty pattern to test.expect()")
if log_act is None:
log_act = INFO
if cmd is not None: if cmd is not None:
if isinstance(cmd, str) and not cmd.endswith('\n'): if isinstance(cmd, str) and not cmd.endswith('\n'):
cmd += '\n' cmd += '\n'
@ -35,7 +37,7 @@ async def expect(conn, cmd=None, regex=None, subject=None, act_timeout=0.1, tota
else: else:
slog(INFO, "reading from console timed out after %d seconds of inactivity" % act_timeout) slog(INFO, "reading from console timed out after %d seconds of inactivity" % act_timeout)
return None return None
slog(INFO, "read from console: >%s<" % buf, only_printable=True) slog(log_act, "read from console: >%s<" % buf, only_printable=True)
if len(buf) == 0: if len(buf) == 0:
raise Exception('connection "{}" reset while waiting on {}'.format(conn, subject)) raise Exception('connection "{}" reset while waiting on {}'.format(conn, subject))
if re.search(regex, buf): if re.search(regex, buf):